I have searched for a similar question here, but surprisingly could not find any.
In GNU bash, there is (a construct? a structure? a data type?) called “arrays“. Arrays are well documented in the bash documentation, so I think that I understand the basics.
But suddenly, in the documentation there also comes up the term “list”. For example, it is used when talking about filename expansion (emphasis is mine):
If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of filenames matching the pattern (see Pattern Matching).
Therefore, I have three questions:
- What does “list” mean here?
- Is it used in the same meaning as in for loop description?
- I am somehow lost in a whitespace world in bash. If this “list” is a separate concept to arrays (as I think), is it treated specially when it comes to whitespaces and
IFS
, or in the same way as an array?
There is another use of the “list” term when talking about sequence of one or more pipelines, but I am aware that it most probably means a different kind of lists.
UPDATE
- Since I see that the way that this “list structure” works is very similar to how arrays work – what are the differences between them?
UPDATE 2
- What are the uses cases when “lists” are preferred over arrays? For example, let us compare. Let us create two files:$ touch file1.txt file2.txt
When it comes to lists, I can do the following:
$ A=*.txt ; echo $A file1.txt file2.txt $
And when it comes to arrays, I can do the following:
$ B=(*.txt) ; echo ${B[@]} file1.txt file2.txt $
While these two results are exactly the same, are there any cases when arrays and lists return different results?
UPDATE 3
I might have confuse something, because in the above example it seems to be a list “wrapped” in an array. I do not know whether it makes a difference.