开发者

How to make an alias of a command which accepts an argument and is executed on background?

开发者 https://www.devze.com 2023-03-20 04:05 出处:网络
I want to make alias to open file with GUI editor on background from comma开发者_运维知识库nd line.

I want to make alias to open file with GUI editor on background from comma开发者_运维知识库nd line.

I tried:

alias new_command="editor_path &"
new_command file

But it just open editor without loading the file.


The & is ending the command, so it is not seeing your file argument. You can't use alias if you want to substitute the filename string into the command with the ampersand on the end.

From the bash manpage:

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

Consider creating a shell function:

function new_command
{
editor_path "$1" &
}


You can try something like this:

alias new_command="sudo -b editor_path"

Although you'd need to enter your password.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号