Home
Categories
WIKI
Topic
User
LANGUAGE:
中文
English
关于 bash 执行异常
Apps Section
405
views ·
5
replies ·
To
floor
Go
不避风云
deepin
2018-11-20 06:28
Author
本帖最后由 bubifengyun 于 2018-11-19 22:31 编辑
执行这个命令
ls +([0-9])
Copy the Code
列出当前文件夹所有数字组成的文件,没有任何问题。但是执行,
$ bash <<< 'ls +([0-9])'
bash:行1: 未预期的符号 `(' 附近有语法错误
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
Like 0
Favorite
View the author
All Replies
funtoo
deepin
2018-11-20 07:14
#1
你混淆了英文单引号(‘)和反引号(`)的作用?
Reply
Like 0
View the author
159******79
deepin
2018-11-20 09:26
#2
应该是你用了单引号。
Reply
Like 0
View the author
不避风云
deepin
2018-11-20 15:18
#3
不是因为单引号的问题。可能换种表达方式更合适。在终端下,可以直接运行 ls +([0-9]),但是放到脚本文件里里就会报错
Reply
Like 0
View the author
不避风云
deepin
2018-11-20 15:20
#4
我不知道在深度终端跟使用脚本有啥区别?竟然报错
Reply
Like 0
View the author
不避风云
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
在脚本里面加上
shopt -s extglob
Copy the Code
即可,不再报错。
Reply
Like 0
View the author
Please
sign
in first
Featured Collection
Change
Nuntia - Modern IMAP/SMTP mail client for Deepin (Beta tester wanted!)
[Tutorial] deepin25 WSL Offline Installation Guide
UOS AI 2.8 Released! Three New Intelligent Agents & Major Evolution
Solid Q&A | deepin 25 Common Questions – The Immutable System Edition
New Thread
Popular Ranking
Change
Taskbar no longer shows popups
Four agent skills for laptop power, sleep, and honest bug reports
Popular Events
More
执行这个命令
我发现使用 bash,sh,dash都是报错的,但是直接输入这个命令却啥也没事。那么问题来了,平常我们打开的深度终端调用的是哪个 shell。谢谢。
参考 /etc/passwd 也是 /bin/bash 啊。