hi,
i store a constant in a variable and want to test whether it is M or Z.
how can i achieve this?? please help
variable='M'
if [ $variable = 'M' ]
then
ehco 'success'
fi;
is this right ??
hi,
i store a constant in a variable and want to test whether it is M or Z.
how can i achieve this?? please help
variable='M'
if [ $variable = 'M' ]
then
ehco 'success'
fi;
is this right ??
i will let somebody else answer that. i prefer case
case $variable in
"M" ) echo "yup " ;;
* ) echo "nope" ;;
esac
Like ghostdog, I prefer to use case, but yours will work (almost).
The variable should be quoted or you will get a syntax error if it is empty.
variable=M
if [ "$variable" = M ]
then
echo success
fi
#