我想要有点帮助我的脚本。 我想在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
)
.

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

有帮助吗?

解决方案

而不是

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

你可以做到:

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top