1

我需要一些关于我的脚本的帮助。我想在 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 或更大,则运行一些命令。接受任何帮助。

4

1 回答 1

3

代替

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

你可以这样做:

if ! grep -q "word" file.txt; then
于 2014-01-11T14:15:07.220 回答