根据给定的输出执行命令

时间:2016-10-10 00:40:03

标签: bash sh

我正在尝试根据另一个脚本的输出执行命令。说:

if [ -f /etc/debian_version]; then 
   DIST="Debian `cat /etc/debian_version`"
fi

OSDIST="$DIST"

# here comes the part where I'm confused

if [ $DIST = Debian 7.x (or if we're being specific here, say 7.9 for example) ]; then 
   execute_some_command
elif [ $DIST = Debian 8.x (or if we're being specific here, say 8.1 for example) ]; then 
    execute_some_other_command
fi

如何在sh中编写类似的内容?我不确定使用哪个参数或选项。谢谢!

1 个答案:

答案 0 :(得分:0)

你也可以尝试这样的事情;

case `cat /etc/debian_version` in

7.7*) echo "VERSION=7.7";
    execute_some_command; 
    ;;

7*) echo "VERSION=7";
    execute_some_command; 
    ;;

8*) echo "VERSION=8";
    execute_some_command; 
   ;;

*) echo "VERSION=NONE";
   execute_some_command; 
   ;;

esac