![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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? |
|
||||
|
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 |
|
||||
|
Quote:
|
|
||||
|
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 |
|
||||
|
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.
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|