I have a simple linux script:
#!/bin/sh
for i in `ls $1`
do
echo $i
done
In my temp folder are 4 file: a.a, a.aa, a.ab and a.ac
When i call ./script temp/*.?? i get:
temp/a.aa
When i call ./script "temp/*.??" i get:
temp/a.aa
temp/a.ab
temp/a.ac
Why do the double quote change the result?
From stackoverflow
Burkhard
-
Because without the quotes the shell is expanding your call to:
./script temp/a.aa temp/a.ab temp/a.acSo
$1istemp/a.aainstead oftemp/*.??.From CesarB -
In the first case the shell expands
temp/*.??to:temp/a.aa temp/a.ab temp/a.acSince you are only looking at the first parameter in your script only
temp/a.aais passed to ls.In the second case, the shell does not perform any expansion because of the quotes and the script receives the single argument
temp/*.??which is expanded in the call tols.From Robert Gamble
0 comments:
Post a Comment