Skip to main content
added 102 characters in body
Source Link
terdon
  • 252.4k
  • 69
  • 480
  • 718

Just read Stéphane's answer.


This happens because of how bash treats globs that do not match anything. To get the same behavior you observe in tcsh, you need to enable bash's nulglob option. From man bash:

nullglob

If set, bash allows patterns which match no files (see Pathname Expansion above) to expand to a null string, rather than themselves.

Enable nullglob with shopt -s nullglob and you will get the expected behavior:

$ ls
bar
$ ls {bar,foo}/*
ls: cannot access 'foo/*': No such file or directory
 bar/ff
$ echo $?
2


$ shopt -s nullglob 
$ ls {bar,foo}/*
bar/ff
$ echo $?
0

This happens because of how bash treats globs that do not match anything. To get the same behavior you observe in tcsh, you need to enable bash's nulglob option. From man bash:

nullglob

If set, bash allows patterns which match no files (see Pathname Expansion above) to expand to a null string, rather than themselves.

Enable nullglob with shopt -s nullglob and you will get the expected behavior:

$ ls
bar
$ ls {bar,foo}/*
ls: cannot access 'foo/*': No such file or directory
 bar/ff
$ echo $?
2


$ shopt -s nullglob 
$ ls {bar,foo}/*
bar/ff
$ echo $?
0

Just read Stéphane's answer.


This happens because of how bash treats globs that do not match anything. To get the same behavior you observe in tcsh, you need to enable bash's nulglob option. From man bash:

nullglob

If set, bash allows patterns which match no files (see Pathname Expansion above) to expand to a null string, rather than themselves.

Enable nullglob with shopt -s nullglob and you will get the expected behavior:

$ ls
bar
$ ls {bar,foo}/*
ls: cannot access 'foo/*': No such file or directory
 bar/ff
$ echo $?
2


$ shopt -s nullglob 
$ ls {bar,foo}/*
bar/ff
$ echo $?
0
Source Link
terdon
  • 252.4k
  • 69
  • 480
  • 718

This happens because of how bash treats globs that do not match anything. To get the same behavior you observe in tcsh, you need to enable bash's nulglob option. From man bash:

nullglob

If set, bash allows patterns which match no files (see Pathname Expansion above) to expand to a null string, rather than themselves.

Enable nullglob with shopt -s nullglob and you will get the expected behavior:

$ ls
bar
$ ls {bar,foo}/*
ls: cannot access 'foo/*': No such file or directory
 bar/ff
$ echo $?
2


$ shopt -s nullglob 
$ ls {bar,foo}/*
bar/ff
$ echo $?
0