this question is not the same as Does the shell support sets?
i know lots of script language support list structure, such as python, python, ruby, and javascript, so what about linux shell?
does shell support such syntax?
for i in list:
do
print i
done
i would first to initialize a list, for example:
ListName = [ item1, item2, ..., itemn ]
then iterate over it
is that possible when programming shell scripts?
for item in list of items; do
construct is certainly supported in all shells. Note also the convenient use of globbing to loop over a set of files;for file in a*.dat
constructs a list of tokens by expanding the wildcard (though sadly, many users manage to wreck it by doing something likefor file in $(ls a*.dat)
). – Mccallum