I'm making a generic bash script whose input $1 is file pattern that it wants to iter through. Right now I have
for entry in ./$1; do
echo "$entry"
done
but when I run this, I get
$ ./stuff.sh PRM*
./PRM.EDTOUT.ZIP
although there are many files of pattern PRM*. Is there a way to specify this pattern in the command line args and list correctly all files of the same pattern?
./stuff.sh PRM*, bash will expand the glob and run./stuff.sh PRM.EDTOUT.ZIP PRM.other.matches.zip. Your script never sees the pattern, it should just loop over all the arguments (for entry in "$@"; do ..or justfor entry; do)./stuff.sh "PRM*". You can also change your script to be a single line:ls $1but you'll still have to quote your input so it doesn't get expanded before the script gets ahold of it.