所以我使用了一个脚本,该脚本根据那里的文件名将特定文件复制到特定文件夹。我想扩展脚本,以便在复制进度后删除文件名中的一部分。这是一个示例,文件名看起来像这个Image_000058_19_12_2019_1920x1080.jpg,我想从中删除分辨率(_1920x1080)部分。 @fedxc为脚本提供了一种将其添加到脚本中的方法(见下文)。
cd "$HOME/Downloads"
# for filename in *; do
find . -type f | while IFS= read filename; do # Look for files in all ~/Download sub-dirs
case "${filename,,*}" in # this syntax emits the value in lowercase: ${var,,*} (bash version 4)
*.part) : ;; # Excludes *.part files from being moved
move.sh) : ;;
# *test*) mv "$filename" "$HOME/TVshows/Glee/" ;; # Using move there is no need to {&& rm "$filename"}
*test*) scp "$filename" "[email protected]:/users/imac/Desktop/" && rm "$filename" ;;
*american*dad*) scp "$filename" "[email protected]:/users/imac/Movies/Series/American\ Dad/" && rm "$filename" ;;
*) echo "Don't know where to put $filename" ;;
esac
done```
我对bash使用变量操作。示例:
export filename='Image_000058_19_12_2019_1920x1080.jpg' <----Setting name of filename
echo ${filename/_1920x1080/} <--Operation with bash variable.
Image_000058_19_12_2019.jpg <--Result of echo
请咨询此页面以获取更多:Bash Guide