Problem
When I run the command "echo ?" then "?" is returned. However,
if I create a filename consisting of one character in the filename
and run the same command it doesn't return "?", it returns the
name of the file I just created.For example:# mkdir /tmp/empty
# cd /tmp/empty
# echo ?
?
# > ab
echo ?
?
# > a
echo ?
a
# > b
echo ?
a b Cause
If a command word includes the "*", "?", or "[" characters,
and the -f flag has not been set, the shell regards the word
as a pattern. The shell replaces the word with file names,
sorted according to the collating sequence in effect in the
current locale, that match that pattern. If the shell does
not find a file name to match the pattern, it does not change
the word.When the shell uses a pattern for file name substitution, the "." and "/" characters must be matched explicitly.
"*" Matches any string, including the null string.
"?" Matches any single character."echo ?" Matches all files of a single character.
"echo ??" Matches all files of two characters.
"echo *" Matches all files, regardless of length.
"echo [Hello]" Matches any file of a single character if that character is "H", "e", "l", or "o".
The basic premise is that a "?" is treated by the shell as a pattern and will match any single character filename as long as one exists. If there is no filename match, then it will return the "?".
Therefore, unlike DOS in which each program has to expand regular expressions ("*" and "?") within the command line, UNIX shells perform the expansion prior to passing the arguments to the command itself.
This means that:# ls ?and# echo ?will be both expanded in the same way to:
# ls a b# echo a b Solution
If you want only "?" displayed, ensure that the "?" is in quotes:
Example:# echo "?" See also
http://www.rs6000.ibm.com/idd500/usr/share/man/info/en_US/a_doc_lib/aixuser/usrosdev/parameter_subst.htmregexp(5) man page on UnixWare/Open UNIX 8 regexp(S) on OpenServer, regex(7) on OpenLinux,
The man page for the shell used.