#intro
if [ -n "$1" ]
then
echo 666
else
echo 555
fi
exit;
Actually I do want to echo 555 while I don't want to do anything in the first block, what should I do? I noticed that I can't just remove echo 666.
#intro
if [ -n "$1" ]
then
echo 666
else
echo 555
fi
exit;
Actually I do want to echo 555 while I don't want to do anything in the first block, what should I do? I noticed that I can't just remove echo 666.
[ -n "$1" ] && echo "666" <= For if part
[ -n "$1" ] || echo "555" <= For else part
You can invert an if statement by using ! (this is called the 'not' operator, which means take the opposite of the result) inside the conditional. So that [ -n "$1" ] becomes:[ ! -n "$1" ], which is the same as the else section.
It's also valid to use the -z option instead of -n which is logically inverse to -n, but as a general rule the ! will always match whatever the else section would match.
trueor:(instead of echo 666) – Archemar Sep 04 '15 at 14:13