如何始终为某些命令附加一个符号? (MacOS / bash)
How to always append an ampersand for certain commands? (MacOS / bash)
每当我打开 emacs 时,我总是想 运行 它在后台运行。我怎样才能做到每当我输入 "emacs xyz" 时 shell 自动 运行s "emacs xyz &"?
您可以创建一个简单的 bash 脚本,任意命名,在本例中假设为 emax
:
#!/usr/bin/env bash
emacs "$@" &
然后调用 emax xyz
下面的 shell 函数(可以放在 .bashrc
中)可以满足您的要求:
emacs() { command emacs "$@" & }
command
确保调用真正的(外部)emacs
命令,而不是让函数递归调用自身。 "$@"
扩展到参数列表,确保它们通过。
每当我打开 emacs 时,我总是想 运行 它在后台运行。我怎样才能做到每当我输入 "emacs xyz" 时 shell 自动 运行s "emacs xyz &"?
您可以创建一个简单的 bash 脚本,任意命名,在本例中假设为 emax
:
#!/usr/bin/env bash
emacs "$@" &
然后调用 emax xyz
下面的 shell 函数(可以放在 .bashrc
中)可以满足您的要求:
emacs() { command emacs "$@" & }
command
确保调用真正的(外部)emacs
命令,而不是让函数递归调用自身。 "$@"
扩展到参数列表,确保它们通过。