Shell script test

bash, command-line, shell

Solution

The command `[` is just an alias of the command `test`, the closing square bracket just being sytax sugar (the command `[` ignores the last argument if it's a closing bracket), so the line actually reads

if test :$RESULT != :0,0

It compares if the string `:$RESULT` equals to the string `:0,0`. The colon is prepended for the case that the variable `$RESULT` is empty. The line would look like the following if the colon was omitted and `$RESULT` was an empty string:

if test  != 0,0

This would lead to an error, since `test` expects an argument before `!=`. An alternative would be to use quotes to indicate that there is an argument, which is an empty string:

if test "$RESULT" != 0,0
# Will become
if test "" != 0,0

The variation you posted is more portable, though.

Problem

I'm tring to update a bash script written by someone else and I've come accross a line I'm not sure about. Can anyone tell me what the following check does: ``` if [ :$RESULT != :0,0 ] ``` I assume it's checking for some value in $RESULT, possibly with a substring? Any help appreciated!

Original source