所以我搞不懂为什么我的“取消”按钮不适用于“确认删除”.你能解释一下吗?
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 $?问题在这个部分,当按下“取消”时,它遵循“确定”按钮路径。
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发布于 2021-01-26 16:59:27
请记住,$?意味着very最后一次命令运行的返回代码。
因此,如果您在运行$?后引用了Sfile=$(basename "$Spath"),那么$?表示basename命令的状态。下一个对$?的引用引用下一个命令。
如果您想测试zenity命令的返回代码,那么应该在调用zenity之后设置ret=$? <#>right (类似于在文件开始时已经做的那样),然后检查$ret的值,而不是$?。
https://unix.stackexchange.com/questions/631111
复制相似问题