在终端中重命名文件的脚本
Script with renaming files in terminal
我正在 bash 中编写脚本来管理文件。我需要添加更改文件名的功能。要获取文件,我使用 zenity 文件选择对话框。执行此操作后,我有一个包含此文件路径的变量:/home/user/Desktop/name_of_file
。如何从此字符串中删除当前文件名并放一个新文件名?
与Bash的Parameter Expansion:
name="/home/user/Desktop/name_of_file"
new="${name%/*}/new_name_of_file"
echo "$new"
输出:
/home/user/Desktop/new_name_of_file
我正在 bash 中编写脚本来管理文件。我需要添加更改文件名的功能。要获取文件,我使用 zenity 文件选择对话框。执行此操作后,我有一个包含此文件路径的变量:/home/user/Desktop/name_of_file
。如何从此字符串中删除当前文件名并放一个新文件名?
与Bash的Parameter Expansion:
name="/home/user/Desktop/name_of_file"
new="${name%/*}/new_name_of_file"
echo "$new"
输出:
/home/user/Desktop/new_name_of_file