Please explain why 1 4 5 6 is displayed for the last four echo statements? I hit this by accident once, but I am now curious as to why this behavior occurs.
These statements work as expected (for me).
$ echo [ 9876543210 ]
[ 9876543210 ]
$ echo [237890]
[237890]
These echo statements consistently display 1 4 5 6. Is there something special about these numbers?
$ echo [9876543210]
1 4 5 6
$ echo [abcd9876543210ghi]
1 4 5 6
$ echo [-123456-]
1 4 5 6
$ echo [-7654321-]
1 4 5 6
Thanks!
- The possible duplicate is related and helpful, but not a duplicate. The possible duplicate is from the perspective of an
rm
command. This question is from the perspective of a perceived "weird behavior" of anecho
command. The underlying answer for both is globbing. Someone searching for issues with anecho
command would not easily find therm
question, but would more likely land here.
1
4
5
and6
nullglob
, your second example (echo [237890]
) will actually print nothing, which could have been a clue that you were seeing glob-expansion in the other examples.