I want to make alias to open file with GUI editor on background from command line.
I tried:
alias new_command="editor_path &"
new_command file
But it just open editor without loading the file.
Bash users need to understand that alias cannot take arguments and parameters. But we can use functions to take arguments and parameters while using alias commands.
Explanation: To declare an alias, the keyword ALIAS is used. Then, the colon sign followed by the name of ALIAS. Then, the name of the object is then specified whose alias is to be created. So, that the duplicate for that object can be created.
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" &
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With