bash user input if

前端 未结 5 1147
没有蜡笔的小新
没有蜡笔的小新 2020-12-25 12:54

I am tring to do simple

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

question in bash.

i tried

echo \"Do that? [Y,n]\"
read DO_T         


        
5条回答
  •  滥情空心
    2020-12-25 13:34

    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 :)

提交回复
热议问题