bash脚本 - 带有if语句的zenity列表

时间:2014-01-11 14:07:15

标签: bash if-statement zenity

我希望我的脚本能有所帮助。 我想在zenity列表中运行一些命令。 这是我的代码

check=$(cat file.txt | grep -c "word")
opt1=$(coomand..)
opt2=$(command..)
opt3=$(command..)

respo=$(zenity  --list  --checklist  --column "Choose" --column "" FALSE "$opt1" FALSE "$opt2" FALSE "$opt3"   --separator=":")
(
[[ $respo = $opt1 ]] && command
[[ $respo = $opt2 ]] && command
[[ $respo = $opt3 ]] && command

if [ $check = "0" ] ; then
:
else
command 1
command 2
command 3
command 4
command 5
command 6
fi
)

我的问题是, if else 语句不起作用。 我想要的是如果 $ check 结果是0然后继续而不运行任何命令。如果结果为1或更大,则运行一些命令。 接受任何帮助。

1 个答案:

答案 0 :(得分:3)

而不是

check=$(cat file.txt | grep -c "word")
if [ $check = "0" ] ; then

你可以这样做:

if ! grep -q "word" file.txt; then