Alex Rivera | Logout

bash user input if

Asked 2011-04-04T17:21:23.663
34

I am trying to do a simple question in bash:

Do you want to do that? [Y,n] _

Tried

echo "Do that? [Y,n]"
read DO_THAT
if ["DO_THAT"="y"]; then
  do_that
fi

but it fails: bash: [y=y]: command not found

what am I doing wrong??!

Edit
Report

1 Answer

21
echo "Do that? [Y,n]"
read input
if [[ $input == "Y" || $input == "y" ]]; then
        echo "do that"
else
        echo "don't do that"
fi

Pay close attention to the syntax and spacing of the if conditional, it gets me all the time in bash :)

answered 2011-04-04T17:24:20.317

Your Answer