Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "-ne" mean in bash?

Tags:

syntax

bash

shell

What does the command "-ne" mean in a bash script?

For instance, what does the following line from a bash script do?

[ $RESULT -ne 0 ]  
like image 690
ZenBalance Avatar asked Jul 17 '13 01:07

ZenBalance


People also ask

What does ne means in Linux?

Following the reference to "Bash Conditional Expressions" will lead you to the description of -ne , which is the numeric inequality operator ("ne" stands for "not equal).

What is NE 0 in shell script?

... is a variable holding the exit code of the last run command. ... checks that the thing on the left ( $? ) is "not equal" to "zero". In UNIX, a command that exits with zero succeeded, while an exit with any other value (1, 2, 3...

What does echo Ne do in bash?

The echo command is one of the most commonly and widely used built-in commands for Linux bash and C shells, that typically used in a scripting language and batch files to display a line of text/string on standard output or a file.

What does [- Z $1 mean in bash?

$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script. Follow this answer to receive notifications.


1 Answers

This is one of those things that can be difficult to search for if you don't already know where to look.

[ is actually a command, not part of the bash shell syntax as you might expect. It happens to be a Bash built-in command, so it's documented in the Bash manual.

There's also an external command that does the same thing; on many systems, it's provided by the GNU Coreutils package.

[ is equivalent to the test command, except that [ requires ] as its last argument, and test does not.

Assuming the bash documentation is installed on your system, if you type info bash and search for 'test' or '[' (the apostrophes are part of the search), you'll find the documentation for the [ command, also known as the test command. If you use man bash instead of info bash, search for ^ *test (the word test at the beginning of a line, following some number of spaces).

Following the reference to "Bash Conditional Expressions" will lead you to the description of -ne, which is the numeric inequality operator ("ne" stands for "not equal). By contrast, != is the string inequality operator.

You can also find bash documentation on the web.

  • Bash reference
  • Bourne shell builtins (including test and [)
  • Bash Conditional Expressions -- (Scroll to the bottom; -ne is under "arg1 OP arg2")
  • POSIX documentation for test

The official definition of the test command is the POSIX standard (to which the bash implementation should conform reasonably well, perhaps with some extensions).

like image 135
Keith Thompson Avatar answered Sep 17 '22 13:09

Keith Thompson