LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-22-2008, 11:32 PM   #1
bichonfrise74
LQ Newbie
 
Registered: Jul 2008
Posts: 24

Rep: Reputation: 15
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
 
Old 10-23-2008, 12:06 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958
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
 
Old 10-23-2008, 01:29 AM   #3
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 820

Rep: Reputation: 197Reputation: 197
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding an alias w3bd3vil Linux - Newbie 1 01-28-2008 04:17 PM
adding IP alias to eth0 via SSH? natv Linux - Networking 4 02-21-2007 04:02 PM
Adding Network Interface alias from command line WireLine Fedora 2 06-08-2005 11:08 PM
adding perm. alias to .bashrc Lleb_KCir Linux - General 7 12-09-2004 02:35 PM
arguments in alias definition bluefire Linux - General 4 11-23-2004 05:48 AM


All times are GMT -5. The time now is 12:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration