mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-05-07 15:28:32 +00:00
Merge pull request #2097 from matteobaglini/master
[bash/en] fix comparison syntax
This commit is contained in:
commit
e16ad03d4a
@ -83,7 +83,7 @@ echo Hello, $Name!
|
|||||||
|
|
||||||
# We have the usual if structure:
|
# We have the usual if structure:
|
||||||
# use 'man test' for more info about conditionals
|
# use 'man test' for more info about conditionals
|
||||||
if [ $Name -ne $USER ]
|
if [ $Name != $USER ]
|
||||||
then
|
then
|
||||||
echo "Your name isn't your username"
|
echo "Your name isn't your username"
|
||||||
else
|
else
|
||||||
@ -91,12 +91,12 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# NOTE: if $Name is empty, bash sees the above condition as:
|
# NOTE: if $Name is empty, bash sees the above condition as:
|
||||||
if [ -ne $USER ]
|
if [ != $USER ]
|
||||||
# which is invalid syntax
|
# which is invalid syntax
|
||||||
# so the "safe" way to use potentially empty variables in bash is:
|
# so the "safe" way to use potentially empty variables in bash is:
|
||||||
if [ "$Name" -ne $USER ] ...
|
if [ "$Name" != $USER ] ...
|
||||||
# which, when $Name is empty, is seen by bash as:
|
# which, when $Name is empty, is seen by bash as:
|
||||||
if [ "" -ne $USER ] ...
|
if [ "" != $USER ] ...
|
||||||
# which works as expected
|
# which works as expected
|
||||||
|
|
||||||
# There is also conditional execution
|
# There is also conditional execution
|
||||||
|
Loading…
Reference in New Issue
Block a user