【问题标题】:bash script - zenity list with if statementbash 脚本 - 带有 if 语句的 zenity 列表
【发布时间】:2014-01-30 13:01:41
【问题描述】:

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

【问题讨论】:

    标签: bash if-statement zenity


    【解决方案1】:

    而不是

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

    你可以这样做:

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

    【讨论】:

    • 是的,对不起。我重新阅读了这个问题并同意(+1)。你怎么反应这么快?我在发布后仅 30 秒就删除了我的评论。
    • 谢谢。我在提醒中看到了你的消息,所以回复了,但后来当我看到你的评论消失时将其删除。
    猜你喜欢
    • 1970-01-01
    • 2017-08-10
    • 1970-01-01
    • 2017-08-15
    • 2014-05-26
    • 2019-08-15
    • 1970-01-01
    • 2012-11-19
    • 2010-10-20
    相关资源
    最近更新 更多