bash - Doubts with for loop in Unix -


sorry if sounds dumb i'm studying exam apply job (administrative one) , learnt , , not scripts. can see it's similar 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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -