How to make an alias of a command which accepts an argument and is executed on background?
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.
精彩评论