Two conditions in a bash if statement

后端 未结 8 2291
失恋的感觉
失恋的感觉 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 08:56

    Another thought,

    $ c1='y' ; c2='y' ; [[ ${c1} = 'y' ]] && [[ ${c2} = 'y' ]] && echo true || echo false  
    true  
    $ c1='n' ; c2='y' ; [[ ${c1} = 'y' ]] && [[ ${c2} = 'y' ]] && echo true || echo false  
    false  
    $ c1='n' ; c2='y' ; [[ ${c1} = 'y' ]] || [[ ${c2} = 'y' ]] && echo true || echo false  
    true  
    $ c1='n' ; c2='n' ; [[ ${c1} = 'y' ]] || [[ ${c2} = 'y' ]] && echo true || echo false  
    false  
    $  
    

    Overflow of gibberish. (;

提交回复
热议问题