If I take the script below, drop it into an empty directory, and execute it, I get:
address@hidden junk# ./test + touch '*' + simple + local file + for file in '*'address@hidden junk# ./test
+ touch '*' + simple + local file + for file in '*' + echo file= '*' test len=1 file= * test len=1 + echo 'file=*' len=1 file=* len=1 + : file= '*' test len=1
+ : 'file=*' len=1 + for file in '*' + echo file= test len=4 file= test len=4 + echo file=test len=4 file=test len=4 + : file= test len=4 + : file=test len=4
+ echo file= '*' test len=1
file= * test len=1 + echo 'file=*' len=1 file=* len=1 + : file= '*' test len=1 + : 'file=*' len=1 + for file in '*' + echo file= test len=4 file= test len=4 + echo file=test len=4
file=test len=4 + : file= test len=4 + : file=test len=4
During execution, there are 2 files referenced - '*' and 'test'. The file named '*' is the one giving me grief.
Can someone explain why when $file contains the asterisk character it gets expanded to the directory contents if and only if $file is surrounded by white space. Note the reported length of the contents of $file. Even when the contents clearly has a length of 1, '* test' gets substituted.
It appears that * is getting expanded again - recursively, and I can't see why that's happening.
================================ #!/bin/bash set -x simple() { local file
for file in *; do
echo file= $file len=${#file} echo file=$file len=${#file} : file= $file len=${#file} : file=$file len=${#file} done }