我正在尝试制作一个 shell 脚本来删除特殊字符,例如 {}()!,' 等。到目前为止,我已经引用了我在这里提出的一个过去的问题,但是我收到了一条奇怪的错误消息:
-bash-3.2$ ./test2.sh
./test2.sh: line 7: unexpected EOF while looking for matching `"'
./test2.sh: line 10: syntax error: unexpected end of file
测试2.sh
#!/bin/bash
shopt -s nullglob
for file in *
do
if [ -f "$file" ]; then
newfile="`echo $file | tr -d '[{}(),\!]' | tr -d "\'" | sed 's/_-_/_/g'`"
mv "$file" "$newfile"
fi
done
不确定我哪里出错了,文件命名如下:
Folder - 01
Folder 02!
Folder(03)
Folder Four_Three
期望的输出是
Folder 01
Folder 02
Folder 03
Folder Four Three
提前谢谢你。
最佳答案
shopt -s extglob
shopt -s nullglob
for i in *; do echo "mv $i ${i//[[:punct:]]/}"; done
关于linux - 删除特殊字符和批量重命名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3800699/