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?
It supports lists, but not as a separate data structure (ignoring arrays for the moment).
The
forloop iterates over a list (in the generic sense) of white-space separated values, regardless of how that list is created, whether literally:or via parameter expansion:
or command substitution:
An array is just a special parameter which can contain a more structured list of value, where each element can itself contain whitespace. Compare the difference: