我正在尝试在 zenity 输入框中执行删除功能。我想知道如何将用户在输入框中提供的路径存储在变量中或如何使用它。谢谢。这是我的代码:
#!/bin/bash
function Ddate() {
zenity --info \
--title "Date and Time" \
--text "Today is $(date)"
}
function Dcalendar() {
zenity --calendar \
--title "Calendar"
}
function Ddelete() {
zenity --entry \
--entry-text "Ex: home/knoppix/" \
--text "Enter a path" \
--title "Delete"
}
while true;
do
choice="$(zenity --height 275 --width 450 \
--list \
--title="Menu" \
--column="Function" --column="Description" \
Date 'Display the actual date and time.' \
Calendar 'Display an interactive calendar.' \
Delete 'Let you delete a file.' \
Exit 'To quit this script.')"
case $choice in
Date) Ddate;;
Calendar) Dcalendar;;
Delete) Ddelete;;
Exit) break;;
esac
done
答案1
通常,如果您想将数据插入“zenity”中的变量中,您可以尝试以下示例:
NAME=$( zenity --entry --text="type your name" )
if [ $? = 0 ] # check if the user click ok on the zenity form
then
echo "Hello $NAME"
else
echo "the user didn't click ok button"
fi
我希望这有帮助。