如何创建一个接受参数并在后台执行的命令的别名?

js_*_*js_ 5 unix macos command-line alias text-editor

我想在命令行的后台使用GUI编辑器创建别名来打开文件.

我试过了:

alias new_command="editor_path &"
new_command file
Run Code Online (Sandbox Code Playgroud)


但它只是打开编辑器而不加载文件.

ant*_*oft 7

&正在结束命令,因此它没有看到您的文件参数.如果要将文件名字符串替换为末尾带有&符号的命令,则不能使用别名.

从bash手册页:

   There  is no mechanism for using arguments in the replacement text.  If
   arguments are needed, a shell function should be  used  (see  FUNCTIONS
   below).
Run Code Online (Sandbox Code Playgroud)

考虑创建一个shell函数:

function new_command
{
editor_path "$1" &
}
Run Code Online (Sandbox Code Playgroud)