Gave up everything else I have to do today to try to read the Bash script here.
What does the "#*" mean instead of an array index in
${line#* }can't find this anywhere and special characters like these are impossible to search for.
Please provide references to documentation when answering.
1 Answer
${parameter%[word]}
Remove Smallest Suffix Pattern. Thewordshall be expanded to produce a pattern. The parameter expansion shall then result inparameter, with the smallest portion of the suffix matched by the pattern deleted. If present,wordshall not begin with an unquoted%.
${parameter%%[word]}
Remove Largest Suffix Pattern. Thewordshall be expanded to produce a pattern. The parameter expansion shall then result inparameter, with the largest portion of the suffix matched by the pattern deleted.
${parameter#[word]}
Remove Smallest Prefix Pattern. Thewordshall be expanded to produce a pattern. The parameter expansion shall then result inparameter, with the smallest portion of the prefix matched by the pattern deleted. If present,wordshall not begin with an unquoted#.
${parameter##[word]}
Remove Largest Prefix Pattern. Thewordshall be expanded to produce a pattern. The parameter expansion shall then result inparameter, with the largest portion of the prefix matched by the pattern deleted.
[emphasis mine]
Source: POSIX documentation. The relevant fragment of Bash Reference Manual: here.
The syntax has nothing to do with arrays.
In particular ${line#* } expands like $line but removes the smallest portion matched by * (asterisk+space, where asterisk matches zero or more characters and space matches space character) from the beginning of it. I.e. it removes characters up to and including the first space from the expansion.
Example:
$ line='foo bar baz'
$ echo "${line#* }"
bar bazIf nothing matches the pattern then nothing will be removed:
$ line='no-match'
$ echo "${line#* }"
no-matchNote ${line#* } only expands to something that can be different than $line. Sole usage of ${line#* } does not redefine the variable:
$ line='foo bar baz'
$ echo "${line#* }"
bar baz
$ echo "$line"
foo bar baz