cat : Do not read stdin if no input file is given on the command line
It seems you have nullglob
enabled so that /path/to/dir/*
expands to nothing if no files are present in /path/to/dir/
. You could, of course, disable nullglob
(shopt -u nullglob
) and get the default behaviour, where /path/to/dir/*
remains as-is if nothing matches and cat
will complain about the non-existent file:
$ cat /path/to/dir/*
cat: '/path/to/dir/*': No such file or directory
You could also just tack on a /dev/null
at the end instead:
$ shopt -s nullglob; cat /path/to/dir/* /dev/null
$ echo $?
0
cat
will get an immediate EOF from /dev/null
, so it will write nothing and quit.