bash - Doubts with for loop in Unix -
sorry if sounds dumb i'm studying exam apply job (administrative one) , learnt java, php, python not unix scripts. can see it's similar php in structure , have many questions .
one of them loop, , why output b*
?
for var in b* echo $var done
i tried code , terminal output b*
, why code answer me text (in case, b*
) or else happen?
a loop in shell scripting takes each whitespace separated string input , assigns variable given, , runs code once each value. in case b*
input , $var
assigned variable.
the shell perform expansion on input. basically, *
acts wildcard part of file name. if have files beginning b in current directory, looped over:
$ ls bean.java bean.class readme.txt $ var in b*; echo $var; done bean.java bean.class
if don't have files beginning b (so pattern b*
doesn't match anything) pattern remain unexpanded:
$ rm bean.* $ ls readme.txt $ var in b*; echo $var; done b*
Comments
Post a Comment