0

Can you help me understand why this happens:

$ echo [023456789]
[023456789]

$ echo [0123456789] 1

With your feedback, I'm hoping I can figure out how to write a bash script that can take an argument with the value of [0123456789] and assign that literal string to a variable.

1 Answers1

5

You have a file named '1' in your current directory.

echo [0123456789]

is a wildcard command that tells bash to display the names of any files in the current directory whose names are comprised of a single digit. If no such files exist, echo will display the wildcard spec itself.

Notice:

$ mkdir /tmp/new-directory
$ cd /tmp/new-directory
$ echo [0123456789]
[0123456789]

$ touch 1 2 4 8 $ echo [0123456789] 1 2 4 8

If you want to display that string literally, instead of displaying the filenames that it matches, enclose the string in quotes:

$ echo "[0123456789]"
[0123456789]
Jim L.
  • 7,997
  • 1
  • 13
  • 27