I recently read that it is dangerous to use unquoted parameter in bash scripts. my question is:
Is it possible to bypass the condition in order to make it always true?
if test $TOTO -eq ${1} 2>/dev/null; then
echo "Bypass"
else
echo "No"
fi
Regards,
R
If you're asking whether you can choose a parameter $1
so that this condition is true for any integer value of $TOTO
, then yes:
./yourscript "0 -o foo"
This makes any condition become
test 1234 -eq 0 -o foo
This is the equivalent of 1234 == 0 || "foo"
in other languages, with one irrelevant comparison OR'd with the truth value of the string foo
.
Since test
considers all non-empty strings to be true, this expression is always true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With