Two conditions in a bash if statement

后端 未结 8 2079
失恋的感觉
失恋的感觉 2020-12-17 08:36

I\'m trying to write a script which will read two choices, and if both of them are \"y\" I want it to say \"Test Done!\" and if one or both of them isn\'t \"y\" I want it to

8条回答
  •  隐瞒了意图╮
    2020-12-17 09:17

    You got the comparison logic backwards; from your description you wanted to say

    if [ "$choice" = 'y' ] && [ "$choice1" = 'y' ]; then
    

    I'm actually surprised that the && construct works, although on further inspection it probably should. Still, I would write it as

    if [ "$choice" = 'y' -a "$choice1" = 'y' ]; then
    

提交回复
热议问题