Skip to content
Advertisement

Is space considered a metacharacter in Bash?

I have searched for the list of metacharacters in Bash but space is not enlisted. I wonder if I’m right by assuming that space is the “token separation character” in Bash, since it not only works as such with Shell programs or builtins but also when creating an array through compound assignment – quotes escape spaces, just like they do most other metacharacters. They cannot be escaped by backslashes, though.
Parameters are passed to programs and functions separated by spaces, for example. Can someone explain how (and when) bash interprets spaces? Thanks!
I’ve written an example:

$ a=(zero one two)

$ echo ${a[0]}

$ zero

$ a=("zero one two")

$ echo ${a[0]}

$ zero one two

Advertisement

Answer

From the man page:

metacharacter
      A character that, when unquoted, separates words.  One of the following:
      |  & ; ( ) < > space tab
                     ^^^^^
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement