Bash Scripting - Conditionals
You want to run a script that prints "Even" if a number is divisible by 2, otherwise "Odd". Which script correctly uses conditionals?
(( )) allows arithmetic expressions and comparisons.(( $num % 2 == 0 )). #!/bin/bash
num=4
if [ $((num % 2)) -eq 0 ]; then
echo "Even"
else
echo "Odd"
fi uses incorrect syntax inside [ ]. #!/bin/bash
num=4
if [ $num % 2 == 0 ]; then
echo "Even"
else
echo "Odd"
fi uses invalid operator inside [ ]. #!/bin/bash
num=4
if [ $num / 2 -eq 0 ]; then
echo "Even"
else
echo "Odd"
fi uses division instead of modulo.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions