linux - 删除特殊字符和批量重命名

标签 linux bash loops shell for-loop

我正在尝试制作一个 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/

相关文章:

linux - Linux脚本的源代码和./执行之间的区别

python - 映射我的软件在 linux 系统上使用的内容

python - 为什么当我激活 virtualenv 时我的提示符没有改变?

c++ - C++ 中的循环不再工作

javascript - 在 vanilla javascript 中将对象列表打印为链接

linux - 在 Linux 中解析 SWF 文件

linux - 将 linux 共享 cifs 挂载为定义的用户而不是 "root"

bash - Sox 批量转换

linux - 完成一组特定的进程后关闭计算机

java - java中数组的while循环问题