Can I safely omit quotes on the right side of a local assignment?function foo {    local myvar=${bar}    stuff()}I'm mainly interested in bash, but any info on corner cases in other shells are welcome.
Are quotes needed for local variable assignment?
shell script;quoting;assignment
Quotes are needed in export foo=$var or local foo=$var (or typeset, declare and other variable declaring commands) in:dashthe sh of NetBSD (also based on the Almquist shell).The sh of FreeBSD 9.2 or older (see the change in 9.3)yashzsh with versions prior to 5.1 in bash or sh emulationAs otherwise the variable expansion would be subject to word splitting and/or filename generation like in any argument to any other command.And are not needed in bash or ksh or the sh of FreeBSD 9.3 or newer (where the command is somehow parsed like some sort of assignment) nor zsh (where word splitting and filename generation is not done implicitly upon variable expansion).They are needed in every shell (except zsh) though in things like:a=b=some valueexport $aOr more generally, if anything left of the = (including the =) is quoted or the result of some expansion (like export 'foo'=$var, export foo\=$var or export foo$((n+=1))=$var (that $((...)) should also be quoted actually)...). Or in other words when the argument to export wouldn't be a valid variable assignment if written without the export.If the export/local command name itself is quoted (even in part like export a=$b, 'ex'port a=$b, \export a=$b, or even export a=$b), the quotes around $b are needed in the cases above and also in bash as well as zsh (all versions) when in sh emulation.If export/local or some part of it is the result of some expansion (like in cmd=export; $cmd a=$b or even export$(:) a=$b) or if export/local is not the first word on the command line (as in dryrun=; $dryrun export a=$b), then the quotes are needed in every shell. In the case of > /dev/null export a=$b however, pdksh and derivatives, the quotes are not needed in bash/AT&T ksh and zsh (they are in pdksh and derivatives).They are not needed in any shell when written:foo=$var export foo(that syntax being also compatible with the Bourne shell).(note that var=value local var shouldn't be used as the behaviour varies across shells).Also beware of this special case with bash:$ bash -c 'IFS=; export a=$*; echo $a' bash a bab$ bash -c 'IFS=; export a=$*; echo $a' bash a ba bMy advise would be to always quote.