I am writing a script in bash to manage files. I need to add a functionality to change files name. To get a file I use zenity File Selection Dialog. After this operation I have a variable with path to this file: /home/user/Desktop/name_of_file
. How can I remove current file name from this string and put there a new one?
With Bash‘s Parameter Expansion:
name="/home/user/Desktop/name_of_file"
new="${name%/*}/new_name_of_file"
echo "$new"
Output:
/home/user/Desktop/new_name_of_file