首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Zenity按钮不工作

Zenity按钮不工作
EN

Unix & Linux用户
提问于 2021-01-26 16:16:53
回答 1查看 557关注 0票数 0

所以我搞不懂为什么我的“取消”按钮不适用于“确认删除”.你能解释一下吗?

代码语言:javascript
复制
directory=$(zenity --entry \
    --text "Enter a path" \
    --title "Delete"\
    --ok-label "Done" )
    ret=$?

    if ((ret==0));then

        if [ -z "$directory" ];then #Check if user entered a path or not.
            directory=$(pwd)    #If not take the actual path.
        fi
        if [ -d "$directory" ];then #Check if entered path exist.
            Spath=$(zenity --file-selection --filename="$directory/" --title "File Browser")
            #Change the directory otherwise will not delete the wanted              file.           
            cd $directory
        fi
        if (($?==0));then
            #Check if the user really want to delete this file.
            zenity --question --icon-name "edit-delete" --title "Confirmation" --text "Are you sure you want to delete this file?"

            #Getting only the file name from the path
            Sfile=$(basename "$Spath")
            echo $?
            clear $?

问题在这个部分,当按下“取消”时,它遵循“确定”按钮路径。

代码语言:javascript
复制
            if (($?==0));then
                rm -f "$Sfile"  #Delete the file.
            elif (($?==1));then
                echo $?
                zenity --error --title "Info" --text "No file was deleted"
            fi      
        fi
        
    else
        #If not existing show error message.
        zenity --error --title "Error" --text "The path you entered does not exist" 
    fi
EN

回答 1

Unix & Linux用户

回答已采纳

发布于 2021-01-26 16:59:27

请记住,$?意味着very最后一次命令运行的返回代码。

因此,如果您在运行$?后引用了Sfile=$(basename "$Spath"),那么$?表示basename命令的状态。下一个对$?的引用引用下一个命令。

如果您想测试zenity命令的返回代码,那么应该在调用zenity之后设置ret=$? <#>right (类似于在文件开始时已经做的那样),然后检查$ret的值,而不是$?

票数 0
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/631111

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档