Question

In linux, in shell scripts, conditions for if statement can be checked using the test command, as below

if test 4 -gt 2; then
echo "4 is bigger than 2"
fi

But there is a more syntatically elegent/common way to write the above, what is it? And think of the real point behind this buboflash question!

if [ 4 -gt 2 ]; then
echo "4 is bigger than 2"
fi

^^ really what this question is demonstrating is that the if statement has as its condition, just some command that either returns success (0) or fail (non-zero) error code and that determines whether the if clause is executed! And the "[ ]" syntax is just a better looking replacement for the test command!

Question

In linux, in shell scripts, conditions for if statement can be checked using the test command, as below

if test 4 -gt 2; then
echo "4 is bigger than 2"
fi

But there is a more syntatically elegent/common way to write the above, what is it? And think of the real point behind this buboflash question!

?

Question

In linux, in shell scripts, conditions for if statement can be checked using the test command, as below

if test 4 -gt 2; then
echo "4 is bigger than 2"
fi

But there is a more syntatically elegent/common way to write the above, what is it? And think of the real point behind this buboflash question!

if [ 4 -gt 2 ]; then
echo "4 is bigger than 2"
fi

^^ really what this question is demonstrating is that the if statement has as its condition, just some command that either returns success (0) or fail (non-zero) error code and that determines whether the if clause is executed! And the "[ ]" syntax is just a better looking replacement for the test command!

If you want to change selection, open document below and click on "Move attachment"

ell by default. 20.7.2 if conditionals The if test ... was used to control program flow in Chapter 7. Bash, however, has a built-in alias for the test function: the left square brace, [ . Using <span>[ instead of test adds only elegance: if [ 5 -le 3 ] ; then echo '5 < 3' fi It is important at this point to realize that the if command understands nothing of arithmetic. It merely executes a command

#### Summary

status measured difficulty not learned 37% [default] 0

No repetitions