I'm trying to understand why an unset variable gets evaluated as 0. in some scripts im writing the variable will be set only if needed and some time it does not. so this kind of behave will result with incorrect output. does it mean i must preset all my variables or at least add check that they are set ?
#!/bin/bash
#myvalue=0 #comment to simulate an unset variable.
if [[ $myvalue -eq 0 ]] ; then
echo "OK"
fi
result with OK:
bash -x test.sh
+ [[ '' -eq 0 ]]
+ echo OK
OK
Aucun commentaire:
Enregistrer un commentaire