Bash

bash 與 zsh 相比的獨特功能

  • September 6, 2013

我成為 zsh 使用者已經有一段時間了(在那個 tcsh 和那個 csh 之前)。我對此感到非常滿意,但想知道是否存在 zsh 中不存在的 bash 的任何引人注目的功能。相反,是否存在 bash 中不存在的 zsh 功能。我目前的感覺是 bash 更好:

  • 如果您已經熟悉它並且不想學習新語法。
  • 預設情況下,它會存在於大多數 *nix 機器上,而 zsh 可能是一個額外的安裝。

不想在這裡開始一場宗教鬥爭,這就是為什麼我只是在尋找僅存在於一個外殼中的功能。

zsh 用於火神。;-)

說真的:bash 4.0 有一些以前只能在 zsh 中找到的功能,比如 ** globbing:

% ls /usr/src/**/Makefile

相當於:

% find /usr/src -name "Makefile"

但顯然更強大。

以我的經驗,bash 的可程式完成性能比 zsh 好一點,至少在某些情況下(例如,為 aptitude 完成 debian 包)。

bash 必須Alt + .插入!$

zsh has expansion of all variables, so you can use e.g.

% rm !$<Tab>

```

for this. zsh can also expand a command in backtics, so



```
% cat `echo blubb | sed 's/u/a/'`<Tab>

```

yields



```
% cat blabb

```

I find it very useful to expand `rm *`, as you can see what would be removed and can maybe remove one or two files from the commmand to prevent them from being deleted.


Also nice: using the output from commands for other commands that do not read from stdin but expect a filename:



```
% diff <(sort foo) <(sort bar)

```

From what I read bash-completion also supports completing remote filenames over ssh if you use ssh-agent, which used to be a good reason to switch to zsh.


Aliases in zsh can be defined to work on the whole line instead of just at the beginning:



```
% alias -g ...="../.."
% cd ...

引用自:https://serverfault.com/questions/4993