I came across this weird parameter expansion for bash/dash which I don't find any reference for. What is this sort of expansion called? Where is it documented?

$ /???
bash: /bin: Is a directory
$ /????
bash: /boot: Is a directory
$ /?????
bash: /cdrom: Is a directory
$ /??????
bash: /libx32: Is a directory
  • The ? behaves as . does in regular expressions; it matches one character. This is documented in your shell's manual. – Kusalananda Aug 1 '18 at 8:30

This is pathname expansion using shell pattern matching: ? matches any single character, so /??? expands to every three-character filename in / in alphabetical order.

That makes /bin first on most systems, which is a directory and not an executable, so you get the error you posted.

This is the same sort of expansion as *, and might be useful for cases like cp file??.txt dest where a set of files have a common structure to their names with only a few fixed characters changing.

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.