In unix land, 0 is true and 1 is false.
For your first example:
if [ 1 ] then echo "Yes" else echo "No" fi
"If" checks the exit code of this command for true / false (ie, zero / non-zero value).
The square brackets actually call the "test" command (see "man test" for more information) and specify the exit code if.
"test 1" (or indeed "test any_string") returns true (0), so "Yes" is output.
For your second example, this prints "No" because "nuxi" was not found in "Linux", if you change "nuxi" to "nux" (maybe it was a typo?) And remove the spaces around = then you get the expected behavior . eg.
word=Linux letter=nux if echo "$word" | grep -q "$letter" then echo "Yes" else echo "No" fi
Nick
source share