【发布时间】:2019-08-28 00:38:36
【问题描述】:
使用模式匹配!("file1") 不能在 bash 脚本中使用,但可以在命令行中使用。
例如:
ls !("file1"|"file2")
这将列出目录中除file1 和file2 之外的所有文件。
在脚本中执行该行时,将显示此错误:
./script.sh: line 1: syntax error near unexpected token `('
./script.sh: line 1: ` ls !("file1"|"file2") '
无论使用什么rm -v !("file1")。发生同样的错误。这是怎么回事,为什么这在脚本中不起作用?
【问题讨论】:
-
使用
source script.sh运行它