作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我目前正在从外部 HDD 运行 Archlinux,因此我正在尝试在 bash 中制作一个脚本,这将允许我更改视频驱动程序,而无需每次从另一台计算机启动时浏览配置文件。
我在台式电脑上使用 nvidia 或 nouveau,但在我女朋友的笔记本电脑上使用 intel。因此,我一直在用 SED 制作一个 bash 脚本,它将当前使用的驱动程序输出到一个名为 $VCARD 的变量,而我想要更改的那个将是脚本的第一个参数($1,然后)。
我的问题是,我试图确保它安全,这样我就不会不小心将包含 nvidia、nouveau 或 intel 的字符串换成这三个字符串以外的任何字符串。我认为实现这一点的最佳方法是进行一系列 if-else 比较,如下所示。
if [ "$1" = "$VCARD" ]
then
echo "Already using $VCARD driver."
else
if [ "$1" = "nouveau" or "intel" or "nvidia" ] #This is the line that concerns me.
then
sed -i -e "7s#\(nouveau\|intel\|nvidia\)#$1#" /etc/X11/xorg.conf.d/10-monitor.conf
echo "New driver is now $1."
else
echo "You don't want to put that string there. (try nouveau, intel or nvidia)"
fi
fi
当您想在中间放置一个逻辑或门时,条件如何工作?
PD:是的,我使用“#”作为 sed 命令的分隔符,我希望这不会对任何人造成影响。
最佳答案
还有:
if [ "$1" = "nouveau"] || [ "$1" = "intel" ] || ["$1" == "nvidia" ]
关于linux - Bash:IF 和 ELSE,比较和逻辑或门?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35997023/
我是一名优秀的程序员,十分优秀!