首先,我有这样简单的脚本
#!/bin/sh
if cat /etc/redhat-release | grep -q 'AlmaLinux'; then
echo "your system is supported"
MY SCRIPT HERE
else
echo "Unsupported OS"
exit0;
fi它可以工作,但我想添加另一个正确的值,它也将返回“您的系统是受支持的”,并让我传递脚本来更进一步。
因此,例如,如果文件/etc/redhat-版本包含AlmaLinux或Rockylinux 8,那么它将同时适用于AlmaLinux和Rockylinux,但如果包含Centos 6,则不会更进一步。
我试过这样做:
#!/bin/sh
if cat '/etc/redhat-release' | grep -q 'AlmaLinux'|| | grep -q 'RockyLinux 8'; then
echo "your system is supported"
else
echo "Unsupported OS"
fi但是它给了我一个错误,我甚至不确定这是否是一个正确的语法。
有谁可以帮我?
发布于 2022-05-19 19:52:08
也许通过使用正则表达式
#!/bin/sh
if cat '/etc/redhat-release' | grep -q -E 'AlmaLinux|RockyLinux 8'; then
echo "your system is supported"
else
echo "Unsupported OS"
fi发布于 2022-05-19 20:09:52
试试这个:
#!/bin/sh
grep -qE 'AlmaLinux|RockyLinux 8' /etc/redhat-release
if [ $? ]; then
echo "your system is supported"
else
echo "Unsupported OS"
fi发布于 2022-05-19 22:29:35
其他完全有效的检测:
#!/bin/sh
NAME=unknown
VERSION='??'
if . /etc/os-release && case $NAME in
*Rocky*)
case $VERSION in
8*) ;;
*) false ;;
esac
;;
*AlmaLinux*) ;;
*) false ;;
esac
then
printf 'Your system %s version %s is supported\n' "$NAME" "$VERSION"
else
printf '%s %s is not supported!\n' "$NAME" "$VERSION" >&2
exit 1
fihttps://stackoverflow.com/questions/72310155
复制相似问题