Zsh and bash are two different programming languages. They're similar, but not identical. In bash, and more generally in Bourne-style shells (sh
, dash
, ksh,
…), an unquoted variable expansion $foo
does the following:
- Take the value of the variable
foo
, which is a string. (If there is no variable foo
, take the empty string.)
- Split the string into whitespace-separated parts. (More generally, the value of the
IFS
variable determines how the string is split; I won't go into all the details here.) The result is a list of strings.
- For every element in the list, if it is a globbing pattern, i.e. if it contains at least one wildcard character
*?\[
(and possibly more depending on some shell options), and that pattern matches at least one file name, then the element is replaced by the list of matching file names. Elements that don't contain any wildcard character, and elements that contain a wildcard character but don't match any file name, are left alone. The result is again a list of strings.
Zsh is mostly a Bourne-style shell, but it has some differences, and this is the main one: $foo
has the following, simpler behavior.
- Take the value of the variable
foo
, which is a string. (If there is no variable foo
, take the empty string.)
- If this results in an empty word, this word is eliminated. (So for example
$foo$bar
is only eliminated if both foo
and bar
are empty or unset.)
Note that in sh or bash, $foo
only works to split a string if it doesn't contain any wildcard character or if globbing is disabled with set -f
.
To split a string at whitespace in zsh, there are two simple methods:
This has nothing to do with oh-my-zsh, which is a plugin to configure zsh for interactive use.
oh-my-zsh
is just a framework for customizing thezsh
shell; if you're usingoh-my-zsh
, then you're usingzsh
(notbash
).zsh
is significantly different from most other shells, so you need to look for documentation aboutzsh
, notbash
or any other shell (and not so muchoh-my-zsh
, because again, it's just a way of customizingzsh
). – Stacistacia