I am trying to understand the output of this command-
The output I see is a single
? 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
Because the ? is split into a word and it contains a glob character (
?) that basically says:
Print the list of filenames in the current directory that match the glob
? match any file with a single character. So, this works:
$ touch a \| b $ echo ? | a b $ ls -l ? -rw-r--r-- 1 user user 0 Dec 29 10:03 '|' -rw-r--r-- 1 user user 0 Dec 29 10:03 a -rw-r--r-- 1 user user 0 Dec 29 10:03 b
If there is no file/directory with one character, this happens:
$ rm a \| b … $ echo ? ?
That is the output in bash with default settings.
To clearly see the files do:
$ ls -l ? ls: cannot access '?': No such file or directory
nullglob is activated, no output will be printed
$ shopt -s nullglob $ echo ? $