3

I need zenity to put a selected filename into a variable without its path. What I have now is

file_to_copy="$(zenity --file-selection --title='Select a File')"
echo $file_to_copy

then prints

/home/blades/Scripts/openwrt-vpn-renew/ze.sh

I wanted to just print ze.sh.

7

If you don't absolutely need zenity to provide this functionality for you, then you can easily do it in the shell, either using parameter expansion

file_to_copy=${file_to_copy##*/}

where ##*/ refers to the longest leading string matching */, or using the basename utility

file_to_copy=$(basename "$file_to_copy")

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.