4 ms·
You don't need quotes in res="$(... whatever ...)" This is sufficient: res=$(... whatever ...)
by posix_me_less 5y ago
You don't need quotes in
res="$(... whatever ...)"
This is sufficient:
res=$(... whatever ...)
- adolph 5y agoIt depends on what is being returned and how the result is used. In my inexpert experience cat $(find -name <some file with spaces in the name>) will fail.
- jolmg 5y agoThey mean specifically on assignment. Though, when in doubt, quoting never hurts.
- nijave 5y agoIt's specifically an edge case with variable assignment. If it were export val="$( ... )" you'd need the quotes again. You don't need quotes in plain variable assignments and afaik it goes back to how space splitting works in Bash (whether or not you're in a "splitting context" or whatever the docs call it). There's a semi-related set of rules for when * gets expanded and when it's passed through to the underlying command as a literal '*' character
- jolmg 5y ago> If it were `export val="$( ... )"` you'd need the quotes again. No. That's also recognized as an assignment by bash[1]: > PARAMETERS... A variable may be assigned to by a statement of the form `name=[value]`... Word splitting is not performed... Assignment statements may also appear as arguments to the alias, declare, typeset, export, readonly, and local builtin commands (declaration commands). [1] https://www.gnu.org/software/bash/manual/bash.html#Shell-Parameters https://www.gnu.org/software/bash/manual/bash.html#Shell-Par...