Bash word splitting mechanism

前端 未结 3 1226
野趣味
野趣味 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:36

    Read man bash. For assignment, it says

    All values undergo tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, and quote removal [ ... ] Word splitting is not performed, with the exception of "$@" as explained below under Special Parameters. Pathname expansion is not performed.

    Word splitting also does not happen in [[ ]] conditions:

    Word splitting and pathname expansion are not performed on the words between the [[ and ]]

提交回复
热议问题