Bash for the loop includes wildcards (* .c) if files with the extension .c. How do i get around?

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 that if there are no files with the extension “c”, it will put “.c” in $ file, and ln -s will create a link to “.c”. Is this a problem? How can I get around this (besides the obvious "if not * .c" hack).

+3
source share
1 answer

you need to set nullglob before loop

shopt -s nullglob

nullglob:                       If set, bash allows patterns that do not match files (see Path Name Extension above) to expand a null string, rather than by themselves.

, reset , :

shopt -u nullglob

.

+8

Source: https://habr.com/ru/post/1794823/


All Articles