gpt4 book ai didi

shell - if 语句 shell 脚本中的多个条件

转载 作者:行者123 更新时间:2023-12-04 13:00:44 28 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





How to represent multiple conditions in a shell if statement?

(8 个回答)


7年前关闭。




我想知道在 if 中是否可以有两个以上的语句编写 shell 脚本时的语句?

username1="BOSS1"
username2="BOSS2"
password1="1234"
password2="4321"

if(($username == $username1)) && (($password == password1)) ||
(($username == $username2)) && (($password == password2)) ; then

这不起作用。但是有没有办法让它发挥作用?

谢谢!

最佳答案

如果使用 /bin/sh您可以使用:

if [ <condition> ] && [ <condition> ]; then
...
fi

如果使用 /bin/bash您可以使用:
if [[ <condition> && <condition> ]]; then
...
fi

关于shell - if 语句 shell 脚本中的多个条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23542574/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com