The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
expanding the size of vg manoj.solaris AIX 2 10-17-2008 06:22 AM
Expanding the root area on SCO 5.07? pschnell SCO 2 10-10-2008 07:00 PM
Alias with variable? JustinT UNIX for Dummies Questions & Answers 1 10-03-2008 10:47 PM
Expanding shell variable lonar Shell Programming and Scripting 2 06-27-2008 12:08 PM
tar expanding trouble TAT2ME74 UNIX for Dummies Questions & Answers 4 08-26-2002 11:35 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-29-2009
locutus01 locutus01 is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 13
expanding alias from a variable

Hi !

I am making my first steps to make a script. Therefore i try to make a scp command more easier. Given is the following alias:

14='admin@x-abcd-def.xyz

Now i want to let the script read three var's from the console to use them in the script and then build the scp string.


Code:
echo "Servernumber:";
read srv="";
echo "remotefile incl. abs. path";
read remotefile="";
echo "localfile incl. abs.path"
read localfile

scp admin@$srv:$remotefile $localfile

Doing it this way $srv is not expanded to the value of the alias. expand_alias is set to on in the bash. So where is my mistake?
  #2 (permalink)  
Old 09-29-2009
dr.house dr.house is offline
Registered User
  
 

Join Date: Dec 2008
Location: Switzerland
Posts: 229

Code:
#! /bin/bash

echo -n "Server no.:  " ; read server
echo -n "Remote file: " ; read remote
echo -n "Local file:  " ; read local

echo "SCP:> $server $remote $local"

exit 0


Code:
[house@leonov] sh test.bash
Server no.:  12
Remote file: this
Local file:  that
SCP:> 12 this that

  #3 (permalink)  
Old 09-29-2009
locutus01 locutus01 is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 13
Quote:
Originally Posted by dr.house View Post
Code:
#! /bin/bash

echo -n "Server no.:  " ; read server
echo -n "Remote file: " ; read remote
echo -n "Local file:  " ; read local

echo "SCP:> $server $remote $local"

exit 0


Code:
[house@leonov] sh test.bash
Server no.:  12
Remote file: this
Local file:  that
SCP:> 12 this that
Ok, but this does not expand the alias for the servername.
  #4 (permalink)  
Old 09-29-2009
peterro peterro is offline
Registered User
  
 

Join Date: Jul 2009
Location: Gresham, OR
Posts: 154
Your code isn't consistent even with similar lines. Remove the semi-colons from the end of the lines. Your 'read' lines aren't the same throughout the script either:


Code:
#!/bin/sh

echo "Servernumber:"
read srv
echo "remotefile incl. abs. path"
read remotefile
echo "localfile incl. abs.path"
read localfile

scp admin@$srv:$remotefile $localfile

A good method for testing techniques/syntax is to pull just the technique out into a simple 2-3 line script to validate that the code works and then put it into your script.

Something like:


Code:
read something
echo $something

or


Code:
srv=box
remotefile=/file
localfile=/another/file
scp admin@$srv:$remotefile $localfile

  #5 (permalink)  
Old 09-29-2009
peterro peterro is offline
Registered User
  
 

Join Date: Jul 2009
Location: Gresham, OR
Posts: 154
Where do the aliases get defined?
  #6 (permalink)  
Old 09-29-2009
locutus01 locutus01 is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 13
Quote:
Originally Posted by peterro View Post
Where do the aliases get defined?
~/.bashrc

Works on the console.
  #7 (permalink)  
Old 09-29-2009
peterro peterro is offline
Registered User
  
 

Join Date: Jul 2009
Location: Gresham, OR
Posts: 154
That wouldn't be part of your script environment though. Are you using these aliases for something else or mainly this? You could source your .bashrc or keep the definitions in a separate file and source that whenever you have a script that needs to access the definitions.
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:13 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0