zsh中奇怪的"工作"行为

Ben*_*ler 15 bash jobs zsh

我正在用怪异的行为jobs,fgbg在我的zsh shell命令.这是一个例子(这适用于所有命令,而不仅仅是python):

$ python &
[1] 21214
Python 2.7.8 (default, Oct 19 2014, 16:02:00)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.54)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
[1]  + 21214 suspended (tty output)  python
$ jobs
[1]  + suspended (tty output)  python
$ fg 1
fg: job not found: 1
$ bg 1
bg: job not found: 1
Run Code Online (Sandbox Code Playgroud)

我在OS X上使用标准的oh-my-zsh安装.

Mic*_*ott 35

您可能习惯于fg N在Bash中工作(其中N是工作号码).但是在Zsh中它有点不同,需要一个%; 例如,fg %1.Bash行为很方便,所以你可以让Zsh做同样的事情:

fg() {
    if [[ $# -eq 1 && $1 = - ]]; then
        builtin fg %-
    else
        builtin fg %"$@"
    fi
}
Run Code Online (Sandbox Code Playgroud)

同样可以做bghistory.这最初来自这个帖子.

  • 或者学习*real*short方式:只需键入`%1`.假定`fg`. (12认同)