LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Alias - Adding Command with Arguments (https://www.linuxquestions.org/questions/linux-newbie-8/alias-adding-command-with-arguments-678464/)

bichonfrise74 10-22-2008 11:32 PM

Alias - Adding Command with Arguments
 
Hi,

In my .bashrc, I have this entry.

alias rm='echo mv $1 /tmp/.rm'

If I try to use this command,
home@home]#> rm test.txt

It will give this output.
home@home]#> echo mv /tmp/.rm test.txt

What I want is actually this output
home@home]#> echo mv test.txt /tmp/.rm

Any ideas?

Thanks,
bichonfrise74

David the H. 10-23-2008 12:06 AM

It's simple. You can't do that with an alias. Aliases are limited to simple substitutions. If you want to do something more complex like this, you need to set it up as a shell function. Create a function and put it in your bashrc, and the command will be available just like an alias would.

A nice short description of aliases and functions can be found at LinuxCommand.org

AnanthaP 10-23-2008 01:29 AM

Also, a single quote is exactly passed, so effectively, the command that is being executed is

'echo mv $1 /tmp/.rm' followed by $1

So maybe, you can substitute double-quotes for single-quotes.

End


All times are GMT -5. The time now is 08:28 PM.