Zenity:获取没有路径的选定文件名

bla*_*des 3 command-line zenity

我需要zenity将选定的文件名放入一个没有路径的变量中。我现在拥有的是

file_to_copy="$(zenity --file-selection --title='Select a File')"
echo $file_to_copy
Run Code Online (Sandbox Code Playgroud)

然后打印

/home/blades/Scripts/openwrt-vpn-renew/ze.sh
Run Code Online (Sandbox Code Playgroud)

我只想打印ze.sh

ste*_*ver 7

如果您不是绝对需要zenity为您提供此功能,那么您可以在 shell 中轻松完成,或者使用参数扩展

file_to_copy=${file_to_copy##*/}
Run Code Online (Sandbox Code Playgroud)

其中##*/指最长的前导字符串匹配*/,或使用该basename实用程序

file_to_copy=$(basename "$file_to_copy")
Run Code Online (Sandbox Code Playgroud)