I'm running the following script at home that I found online and every time I do, the shell terminates when I supply an answer to the read prompt. When I run the script in the bg, I get the following message: Bash: [answer]: command not found. Why is this happening? I usually run it from the directory the script is kept using .
Edit: I ran the script with bash
instead, and the script worked as expected. Can anyone explain why the difference?
#!/bin/bash
echo "Enter 1 or 2, to set the environmental variable EVAR to Yes or No"
read ans
# Set up a return code
RC=0
if [ $ans -eq 1 ]
then
export EVAR="Yes"
else
if [ $ans -eq 2 ]
then
export EVAR="No"
else
# can only reach here with a bad answer
export EVAR="Unknown"
RC=1
fi
fi
echo "The value of EVAR is: $EVAR"
exit $RC