<分区>
我在 UNIX (sparc 10) 上使用 bash
for file in $SCPATH/$LIBNAME/*.{gob,c,cpp,h};
do
ln -s $file;
done;
问题是:如果没有扩展名为 'c' 的文件,它会将 ".c"放入 $file 中,ln -s 将创建指向 '.c' 的链接。 这是一个已知问题吗?我怎样才能绕过它(除了明显的“if not *.c”黑客攻击)。
<分区>
我在 UNIX (sparc 10) 上使用 bash
for file in $SCPATH/$LIBNAME/*.{gob,c,cpp,h};
do
ln -s $file;
done;
问题是:如果没有扩展名为 'c' 的文件,它会将 ".c"放入 $file 中,ln -s 将创建指向 '.c' 的链接。 这是一个已知问题吗?我怎样才能绕过它(除了明显的“if not *.c”黑客攻击)。
最佳答案
你需要在循环之前设置 nullglob
shopt -s nullglob
nullglob: If set, bash allows patterns which match no files (see Pathname Expansion above) to expand to a null string, rather than themselves.
当您完成并想要将其重置为原始行为时,请使用:
shopt -u nullglob
正如 Dennis Williamson 在其中一条评论中指出的那样。
关于bash - 如果没有扩展名为 .c 的文件,则 for 循环包括通配符 (*.c)。我怎么走?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5123135/