Question

I noticed that when I try to echo ?, it prints 1.

I read that it is a "wild card (single character). [question mark] The ? character serves as a single-character "wild card" for filename expansion in globbing, as well as representing one character in an extended regular expression." (as written in a documents titled "Advanced Bash-Scripting Guide: A complete guide to shell scripting, using Bash" that I read on the web).

$ echo ?
1

$ echo ? ? ?
1 1 1

$ echo ? 1 ?
1 1 1

$ ls shai?n
shai.txt

bash --version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
Was it helpful?

Solution

  • ? expands to all one character files or itself if none exists
  • * expands to all files or itself if none eixsts

So only way this can happen is if you have a single-character file called 1 in your working directory. e.g.

> mkdir emptydir && cd emptydir 
> echo ?
?
> touch 1 && echo ?
1

Also note as comments point out you can print it by doing echo "?" or echo \?

OTHER TIPS

You probably have a file called '1' in the current working directory.

# echo ?
?

# touch 1
# echo ?
1

With bash's nullglob option, you can suppress printing the glob pattern as a string:

$ echo ?
?
$ shopt -s nullglob
$ echo ?

$ touch A
$ echo ?
A
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top