According to tldp.org, bash underscore variable is:
The underscore variable is set at shell startup and contains the absolute file name of the shell or script being executed as passed in the argument list. Subsequently, it expands to the last argument to the previous command, after expansion. It is also set to the full pathname of each command executed and placed in the environment exported to that command. When checking mail, this parameter holds the name of the mail file.
But this answer to How can I repeat a character in Bash? makes an strange use of it:
# exactly the same as perl -E 'say "=" x 100'.
echo -e ''$_{1..100}'\b='
Playing around with this variable I can't make anything out of it's semantics, so the question is what does
- An string.
- Followed by
$_
. - Followed by range expansion.
- Followed by another string
mean in bash?
Sample:
$ echo $_{0..10} ; echo $_{0..10} | wc
1 0 1
$ echo ''$_{0..10}'' ; echo ''$_{0..10}'' | wc
1 0 11
$ echo ''$_{0..10}'x' ; echo ''$_{0..10}'x' | wc
x x x x x x x x x x x
1 11 22
$ echo 'x'$_{0..10}'' ; echo 'x'$_{0..10}'' | wc
x x x x x x x x x x x
1 11 22
$ echo 'ab'$_{0..10}'cd' ; echo 'ab'$_{0..10}'cd' | wc
abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd
1 11 55