关于 bash 执行异常
Tofloor
poster avatar
不避风云
deepin
2018-11-20 06:28
Author
本帖最后由 bubifengyun 于 2018-11-19 22:31 编辑

执行这个命令
  1. ls +([0-9])
Copy the Code
列出当前文件夹所有数字组成的文件,没有任何问题。但是执行,
  1. $ bash <<< 'ls +([0-9])'
  2. bash:行1: 未预期的符号 `(' 附近有语法错误
  3. bash:行1: `ls +([0-9])'
Copy the Code
就弹出异常了。查资料说是 dash 搞的鬼,https://blog.csdn.net/u014470581/article/details/51493150
我发现使用 bash,sh,dash都是报错的,但是直接输入这个命令却啥也没事。那么问题来了,平常我们打开的深度终端调用的是哪个 shell。谢谢。

参考 /etc/passwd 也是 /bin/bash 啊。



Reply Favorite View the author
All Replies
avatar
funtoo
deepin
2018-11-20 07:14
#1
你混淆了英文单引号(‘)和反引号(`)的作用?
Reply View the author
avatar
159******79
deepin
2018-11-20 09:26
#2
应该是你用了单引号。
Reply View the author
avatar
不避风云
deepin
2018-11-20 15:18
#3
不是因为单引号的问题。可能换种表达方式更合适。在终端下,可以直接运行 ls +([0-9]),但是放到脚本文件里里就会报错
Reply View the author
avatar
不避风云
deepin
2018-11-20 15:20
#4
我不知道在深度终端跟使用脚本有啥区别?竟然报错
Reply View the author
avatar
不避风云
deepin
2018-11-21 01:55
#5
已解决,https://bbs.deepin.org/user/39396 https://bbs.deepin.org/user/10700 是因为没有支持glob格式,参考网页:https://unix.stackexchange.com/q ... es-this-work-ls-0-9

在脚本里面加上
  1. shopt -s extglob
Copy the Code

即可,不再报错。
Reply View the author