linux - 我想通过 shell 删除所有文件,除了少数 as 但导致语法错误 : "(" unexpected

标签 linux bash shell ubuntu

rm -rf  * ! ( "update.sh" | "new_update"  )    #or


rm -rf   ! ( "update.sh" | "new_update"  )     #or


rm -rf   ! ( update.sh | new_update  )         #or
我想删除除 update.sh 之外的所有文件和 new_update我已经厌倦了shell脚本中的所有行但返回错误

unexpected token (


当直接在终端上运行时,有时会执行,有时会出现与上述相同的错误

最佳答案

首先,您必须启用扩展通配符

shopt -s extglob
那么你不能在通配符的各个部分之间有空格。
rm -rf !(update.sh|new_update)

关于linux - 我想通过 shell 删除所有文件,除了少数 as 但导致语法错误 : "(" unexpected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67592301/

相关文章:

linux - ifconfig 似乎不同意 Centos 网络连接偏好

linux - 如何在 Linux 中打印处理器的一个特定核心上列出的所有进程?

bash - 使用华为 E8372 hilink 通过 bash 脚本发送短信

当使用 crontab 计划脚本时,Oracle SQLPlus 假脱机命令不起作用?

linux - 编辑文件时保留时间戳

bash - 在 heredoc 部分设置变量

python - 如何修复错误 : django. db.utils.NotSupportedError:不支持 URI

linux - 如何注释文件中的缩进行

linux - Bash脚本的正确缩进

python - python的Hadoop命令