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.

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?

#! /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
[house@leonov] sh test.bash
Server no.:  12
Remote file: this
Local file:  that
SCP:> 12 this that

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:

#!/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:

read something
echo $something

or

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

Ok, but this does not expand the alias for the servername.

Where do the aliases get defined?

~/.bashrc

Works on the console.

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.

Even though this could work (reference), I'd rather try to keep things separate (- a basic setup I'm using for larger projects: script.main for the main part, script.code for functions and script.data for variables).

--

Further details: ABS on Aliases