0

From a linux terminal the command:

 ls application/js/{a*,b*,c*,d*,e.pocket-secure}

Will list all files in the application/js directory that start with a,b,c,d or e.pocket-secure.

If I place that command in doit.sh and execute:

sh doit.sh

I get:

ls: cannot access application/js/{a*,b*,c*,d*,e.pocket-secure*}: No such file or directory

I think the {} is confusing the shell interpreter, but I tried quoting (single|double) and also tried escaping the {} to no avail.

4

2 回答 2

2

当您在终端中键入时,我怀疑您在bash. 当你运行时sh doit.sh,你正在改变 shell 的特性,要么是因为bash处于兼容模式,要么是因为你正在使用类似dash. 尝试做bash doit.sh

于 2012-12-15T05:13:05.913 回答
1

这种语法只适用于 bash 解释器你可以试试这个

#/bin/bash
ls application/js/{a*,b*,c*,d*,e.pocket-secure}

chmod +x doit.sh
./doit.sh

或者

只需在 shell 上输入

bash doit.sh
于 2012-12-17T16:44:27.637 回答