Bash word splitting mechanism

前端 未结 3 1211
野趣味
野趣味 2020-12-06 04:09

I am new to Bash and I am seeing that there is automatic word splitting done by Bash:

a=\"1  2     3 4\"

If I echo \"a\" by echo $a

3条回答
  •  庸人自扰
    2020-12-06 04:40

    Bash works as next - when parsing a script or command line:

    1. parsing and lexical analysis
    2. expansion
      1. brace expansion
      2. tidle expansion
      3. variable expansion
      4. artithmetic and other substitutions
      5. command substitution
      6. word splitting
      7. filename generation (globbing)
    3. removing quotes

    as you can see, the word splitting is nearly at the end, so after the e.g. arithmetic exansion but before the filename globbing, Removing the quotes is the last step.

提交回复
热议问题