1

This is such a simple question that I'm sure it's been asked somewhere, but I can't find it. My shell, which I have not intentionally set up to do so, seems to eat any words involving question marks:

$ bash --version
GNU bash, version 4.3.42(1)-release (x86_64-apple-darwin13.4.0)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ echo a ? = =?
a =

$ not-a-command? echo a
a

$ (?) echo a
a

In case it matters, note that any word containing a question mark seems to disappear completely silently—to the extent that she shell never even notices that the invocation starts with a word that doesn't specify a valid executable—even if the question mark is not at the beginning.

6

You probably have the nullglob shell option enabled; this causes any word containing a globbing character (* or ?) to be removed if the glob doesn't match anything. Thus, if you're in a folder which doesn't contain any file, folder etc. with a single-character name, ? won't expand to anything and will instead be removed; likewise, not-a-command? is unlikely to match anything and will instead be removed.

To check whether this is the case, run

shopt nullglob

To de-activate the option, run

shopt -u nullglob
2

it's like *, but it represents a single character

e.g. show the three-character root directories:

$ ls -d /???
/bin  /dev  /etc  /lib  /mnt  /opt  /run  /sys  /tmp  /usr  /var

note that /home is not shown because it doesn't match

Use [?] or \? or wrap your strings in quotation marks ("foo?" or 'bar?')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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