If I run a code like this:
./script *.txt
*.txt will be expanded to all files with .txt extension. But if there is no such file, script will be called with *.txt string. I wonder if there is a way to force expansion to "" when there is no such file. So it means if there is no such file, the script will be called without any argument.
Any idea?
nullglobshell option (set withshopt -s nullglob) - see Why is nullglob not default?./script ''/./script ""is not the same as./script. The latter will call script with no argument, while the former will call it with one empty argument../script *.txt(N)in zsh (where the nullglob option also comes from). Do you have to usebash?[ -e "$1" ]if the first argument exists in the filesystem, and if it does, continue processing as usual?