bash的for循环,包括如果与扩展.C任何文件野生字符(* .c)中。我该如何解决? [英] bash for loop includes wild characters (*.c) if no files with extension .c. How do I get around?

查看:87
本文介绍了bash的for循环,包括如果与扩展.C任何文件野生字符(* .c)中。我该如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用UNIX上的bash(SPARC 10)

 在$ SCPATH / $ LIBNAME / * {采空区,C,CPP,H}文件。

    LN -s $文件;
完成的;

问题是:是否有与扩展名为'C'没有文件,就会把 .C在$文件和LN -s将创建一个链接到的.C'。
这是一个已知问题?我怎样才能避开它(除了明显的如果不是的* .c破解版)。


解决方案

你需要你的循环之前设置nullglob

 禁用了javascript -s nullglob


  

nullglob:
                        如果设置,bash允许没有匹配的文件哪些模式
  (见上文路径扩展),以
  扩展为一个空字符串,而不是
  他们自己。


当你完成,并希望将其恢复到原来的行为,是:

 禁用了javascript -u nullglob

正如丹尼斯·威廉姆森在评论一个人指出。

I am using bash on UNIX (sparc 10)

for file in $SCPATH/$LIBNAME/*.{gob,c,cpp,h};
do
    ln -s $file;
done;

The problem is: if there are no files with extension 'c', it will put ".c" in $file and ln -s will create a link to '.c'. Is this a know issue? How can I get around it (besides the obvious 'if not *.c' hack).

解决方案

you need to set nullglob before your loop

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.

When you're done and want to reset it to the original behavior, use:

shopt -u nullglob

As pointed out by Dennis Williamson in one of the comments.

这篇关于bash的for循环,包括如果与扩展.C任何文件野生字符(* .c)中。我该如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆