I'm quite new to Bash scripting. I have a "testscript", which I used as the basis for a more advanced / useful script:
#!/bin/bash
files=$1
for a in $files
do
echo "$a"
done
When I call this without any quotes it just picks up one file in a directory:
testscript *.txt
But when I call it with quotes it works correctly and picks out all the text files:
testscript '*.txt'
What is going on here?
for a in "$@"; do
(orfor a; do
) in your script, thus leaving the globbing to the outer shell, not to leave out the quotes. – Charles Duffy Aug 26 '16 at 23:10