LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 06-06-2005, 02:22 PM   #1
gjr
LQ Newbie
 
Registered: Jun 2005
Posts: 3

Rep: Reputation: 0
setting up scp alias under bash - parameter passing problem


I am a newbie at using paramters in my bashrc (or a file function), and while I eventually
converged on a solution in all other case, an alias for scp . To be concrete, the following
alias

alias scpm1="scp $1 userid@100.1.1.1.:/home/userid"

does not work (nor do these commands in a bash script file). An example of the error message
is as follows

joe@100.1.1.1 :scpm1 mozilla.ps
joe@ 100.1.1.1 's password:
scp: /home/joe/.: not a regular file

It does not matter if I place the intended location in single or double quotes. This command by itself,
not as an alias, and not as a bash script (such as)
#!/bin/bash
scp $1 userid@100.1.1.1.:/home/userid
(with $1 substituted by the filename)
works fine.

Thanks for any assistance that you can provide
 
Old 06-07-2005, 07:24 AM   #2
huibert.alblas
Member
 
Registered: Jan 2004
Location: Duesseldorf /Germany
Distribution: Gentoo amd64 / Debian
Posts: 226

Rep: Reputation: 30
AFAIK it is not possible to do VaraibleSubstitution with aliases.

Bash will exand the command "scpm1 TESTING" in place to
"scp $1 userid@100.1.1.1.:/home/userid TESTING"
whicj looks like "scp userid@100.1.1.1.:/home/userid TESTING"
Because $1 is empty...


The script you wrote will work for exact the same reason.

Congrats, you found the difference between a (short) shellscript and a command allias.
Here's your t-shirt :-)


Happy hacking!
 
Old 06-07-2005, 07:35 AM   #3
gjr
LQ Newbie
 
Registered: Jun 2005
Posts: 3

Original Poster
Rep: Reputation: 0
sorry that my verbiage was unclear - the script file does not work, and, in fact, generates
the same error message that the alias does. So, somehow variable substitutions are not
working in the script I have defined.
 
Old 06-08-2005, 01:39 AM   #4
huibert.alblas
Member
 
Registered: Jan 2004
Location: Duesseldorf /Germany
Distribution: Gentoo amd64 / Debian
Posts: 226

Rep: Reputation: 30
But your scrit is perfectly ok,
I just tested it. (but I knew it would work all the time :-)

Are you using the same name fore the script as for the alias?
If so, bash would do the alias substitution first, so you script will never get executed.

Try calling your script directly like:
Code:
/path/to/script/scpm1 SOME_PARAM
 
Old 06-08-2005, 06:38 AM   #5
gjr
LQ Newbie
 
Registered: Jun 2005
Posts: 3

Original Poster
Rep: Reputation: 0
I used unalias to clear the old alias, and then it works fine - thanks for continuing this thread, as this simple script (and one's like it) will save me lots of time (and save me from lots of typing mistakes).
 
  


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
setting alias in bash, permanently allelopath Linux - General 6 10-24-2008 04:10 AM
bash parameter indirection possible? kornelix Programming 5 11-30-2005 08:35 AM
Passing hash of hashes as a parameter (Perl) rose_bud4201 Programming 8 04-21-2005 07:18 PM
Passing parameter to kernel when booting from floppy NewtoSlack Slackware 1 10-10-2003 08:24 PM
parameter passing mechanisms dhanakom Programming 2 09-01-2003 04:15 PM


All times are GMT -5. The time now is 01:45 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration