For a more extensive answer, read https://apple.stackexchange.com/questions/361870/what-are-the-practical-differences-between-bash-and-zsh/361957#361957
There's already been quite a bit of activity on the topic on other Stack Exchange sites. My experience of switching from bash to zsh, as far as can remember (it was years ago²), is that I didn't miss a single thing. I gained a lot; here are what I think are the simple zsh-specific features that I use most:
The zsh feature I most miss when I occasionally use bash is autocd: in zsh, executing a directory means changing to it, provided you turn on the autocd
option.⁴
Another very useful feature is the fancy globbing. The hieroglyphscharacters are a bit hard to remember but extremely convenient (as in, it's often faster to look them up than to write the equivalent find
command). A few of the simpler examples:
foo*~*.bak
= all matches for foo*
except those matching *.bak
foo*(.)
= only regular files matching foo*
foo*(/)
= only directories matching foo*
foo*(-@)
= only dangling symbolic links matching foo*
foo*(om[1,10])
= the 10 most recent files matching foo*
foo*(Lm+1)
= only files of size > 1MB
dir/**/foo*
= foo*
in the directory dir
and all its subdirectories, recursively⁴
For fancy renames, the zmv
builtin can be handy. For example, to copy every file
to file.bak
: zmv -C '(*)(#q.)' '$1.bak'
Both bash and zsh have a decent completion system that needs to be turned on explicitly (. /etc/bash_completion
or autoload -U compinit; compinit
). Zsh's is much more configurable and generally fancier.
If you run zsh without a .zshrc
, it starts an interactive menu that lets you choose configuration options. (Some distributions may disable this; in that case, run autoload zsh-newuser-install; zsh-newuser-install
.) I recommend enabling the recommended history options, turning on (“new-style”) completion, and turning on the “common shell options” except beep
. Later, configure more options as you discover them.
²At the time programmable completion was zsh's killer feature, but bash acquired it soon after.
⁴Features that bash acquired only in version 4 (so were not widely available at the time this answer was posted, and are not available on the system-provided bash on macOS) are in smaller type.
Yes. Forking is spelled &
:
echo child & echo parent
What may be confusing you is that $$
is not the PID of the shell process, it's the PID of the original shell process. The point of making it this way is that $$
is a unique identifier for a particular instance of the shell script: it doesn't change during the script's execution, and it's different from $$
in any other concurrently running script. One way to get the shell process's actual PID is sh -c 'echo $PPID'
.
The control flow in the shell isn't the same as C. If in C you'd write
first(); fork(); second(); third();
then a shell equivalent is
after_fork () { second; third; }
first; after_fork & after_fork
The simple shell form first; child & parent
corresponds to the usual C idiom
first(); if (fork()) parent(); else child();
&
and $$
exist and behave this way in every Bourne-style shell and in (t)csh. $PPID
didn't exist in the orignal Bourne shell but is in POSIX (so it's in ash, bash, ksh, zsh, …).
Best Answer
Unfortunatly not. But I predict, that bash will massively slow down if you try to implement these features. Perhaps that's why noone "ported" these features yet.
The nearest I found was https://github.com/dvorka/hstr, a shell suggestion box
aside bash:
I didn't tested it, but the only "ported alternative" that I found was written for
zsh
: https://github.com/zsh-users/zsh-autosuggestionsSome qwant'ing also lead me to https://websetnet.com/shell-packs-power-python-bash/ and https://github.com/xonsh/xonsh alias http://xon.sh, perhaps it also supports that out of the box
... but, I'm quite sure you're not interested in other alternatives to bash, because then you could just switch to fish ;)