Linux shell script, checking input from user -
so i'm making simple bash shell script calculator , ran snag.
i can't seem find out see if user has inputted + or - or / or *
i'm not sure should try write. know
echo "enter + or - " read input2 if [ $input2 = "+" ] echo "you entered $input2" doesn't work. should put read basic operators?
edit: bash shell being used
in bash, semicolon or newline needed before then.
double quotes variables prevent expansion might lead syntax errors:
if [ "$input" = '+' ] ; you can switch [[ ... ]] conditionals don't require quoting of arguments:
if [[ $input = + ]] ; echo entered + fi you have quote * on right hand side, though, otherwise it's interpreted wildcard pattern, meaning "anything".
Comments
Post a Comment