How to split a variable in zsh shell?
See the description of the shell option SH_WORD_SPLIT in the section ‘Parameter Expansion’ in zshexpn (1). In zsh, you can either explicitly request the splitting (e.g. $ {=foo}) or use an array when you want a variable to expand to more than one word.
How to make shell script work with zsh?
If you want the script to work in every shell, you need to use the positional parameters. They are the only array available. If you have a shell script that you want to be able to run conveniently with zsh, put this line at the beginning — it tells zsh to act like ksh, and it’s a no-op on other shells.
What is the mystery variable in zsh Stack Overflow?
In experimentation on the shell itself it seems to indicate the [] is some arithmetic thing, which makes sense, but I don’t see the part that explains how (w) is supposed to work. It seems to be some magical operator that applies to the math expression…
When to do globbing in sh file expansion?
If the SH_FILE_EXPANSION option is set, the order of expansion is modified for compatibility with sh and ksh. In that case filename expansion is performed immediately after alias expansion , preceding the set of five expansions mentioned above. This expansion, commonly referred to as globbing, is always done last.
How to assign space containing values to variables in Bash?
However, when the variable value contains spaces, eval returns an error, even if $var_value is put between double quotes: Any way to circumvent this ? Don’t use eval for this; use declare. Note that word-splitting is not an issue, because everything following the = is treated as the value by declare, not just the first word.
Can you use a local variable in Bash?
So you can’t use it for instance in things like: Because that would declare a foo variable local to setvar so would be useless.