LinuxQuestions.org
Visit Jeremy's Blog.
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 08-22-2014, 12:03 PM   #1
CommanderRikker
LQ Newbie
 
Registered: Aug 2014
Posts: 7

Rep: Reputation: Disabled
alias has unwanted space in it


Hi gang:

I'm trying to create an alias that will copy my public key to other servers. I created this alias in .bashrc:
Code:
alias copykey='ssh-copy-id root@$1'
However, when I type this at a command line:
Code:
copykey server1
I get:
Code:
ssh-copy-id root@ server1
How do I get rid of that space before the server name?

Thanks,

Rick
 
Old 08-22-2014, 12:26 PM   #2
thesnow
Member
 
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 170

Rep: Reputation: 56
Try a function instead (in your .bashrc)

Code:
function copykey { ssh-copy-id root@"$1"; }
ouputs:
Code:
user@lm ~ $ copykey server1
+ copykey server1
+ ssh-copy-id root@server1
 
1 members found this post helpful.
Old 08-23-2014, 12:35 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,256

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
thesnow is correct, but I thought I would provide the explanation for your issue.

Aliases do not accept parameters and even if they did you would not get the desired result. You need to think of the alias as a cut and paste.
So whatever you assign to your alias will directly replace the name of the alias. So if you could accept parameters, your output would have looked like:
Code:
$ alias copykey='ssh-copy-id root@$1'
$ copykey server1
$ ssh-copy-id root@server1 server1
 
1 members found this post helpful.
  


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
bash script to display alias commands and un-alias any less than 12 characters bani Linux - Newbie 5 01-19-2014 01:34 PM
LXer: alias.sh puts your Linux shell alias on the clouds LXer Syndicated Linux News 0 01-21-2013 01:00 AM
Wildcard email alias in /etc/alias file custangro Linux - Enterprise 1 10-02-2009 01:17 PM
Alias question (2 commands for one alias) gflores Linux - Newbie 3 01-21-2006 01:40 AM
Space in alias Ironica Linux - General 3 06-16-2004 06:25 PM


All times are GMT -5. The time now is 11:02 AM.

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