Reputation: 2119
For instance:
if $input = 'y'
causes
./test.sh: line 5: y: command not found
While
if [ $tmp = 'y' ]
causes no error?
What is the purpose of an if statement that cannot evaluate conditions?
Upvotes: 0
Views: 203
Reputation: 17517
if
doesn't evaluate anything. It simply executes the predicate program and acts on its return code. [
is actually a program that does a handful of conditions, and returns an appropriate return code.
[
can be used with oneliners without if, if you don't need the else
branch:
$ [ 1 -eq 2 ] && echo "foo"
# -> no output
Upvotes: 3