This question already has an answer here:

While doing some work, I came across this

$ echo [Login]
$ echo [kilo]
$ echo [gauke]
  e g k
$ echo [quasi-star]
  k m q

What is going on in the background that results in this output ? Output of echo [quasi-star] just lost it's mind giving letters that are not even in there.

Note: Yes I know I can get my output with echo "[Login]"

marked as duplicate by Jeff Schaller, GypsyCosmonaut, Community Aug 7 '17 at 11:06

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Without the quotes, the shell is doing pathname (glob) expansion on the character class [], so presumably you have files named e, g, k, m, q in the current directory -- hence the result.

echo is basically just printing the result of pathname expansion, nothing more.

Let's take one example, echo [quasi-star]:

The result of expansion for [quasi-star] would be any single character from quasijklmnopqrstar (duplicates are kept intentionally). From shell's perspective, as there are no surrounding characters, so it would just match any single character filename on the current directory from the expansion.

  • If I type echo [kilo] on my machine, the output ist [kilo] and in this directory is no file with an k, i or l in it's filename. – John Goofy Aug 7 '17 at 11:04
  • @JohnGoofy Yes, that's expected (literal value), unless you have nullglob/failglob (assuming bash) set. – heemayl Aug 7 '17 at 11:07
  • @heemayl But why there is only with [kilo] a literal echou output? – John Goofy Aug 7 '17 at 11:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.