Bash – why echo ? is returning a single | character to the stdout

bashshellwildcards

I am trying to understand the output of this command- echo ?.
The output I see is a single | charcter.

Best Answer

Because ? is a special wildcard character for the shell. $abc is not present, so it's expanded to an empty string, and ? is replaced by any one-character file or directory existing in the current directory. So, there probably is a file/directory named | in your current directory.

On my system, the output is different:

$ echo $abc?
_ 1

If there's no one-character file/directory, the ? comes out unexpanded.

And, indeed, there are directories _ and 1.

Related Question