Do you want BuboFlash to help you learning these things? Or do you want to add or correct something? Click here to log in or create user.



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!

Answer

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!

Answer
?

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!

Answer

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"

20. Advanced Shell Scripting
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

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Details

No repetitions


Discussion

Do you want to join discussion? Click here to log in or create user.