Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

howto use my alias's from .bashrc 1

Status
Not open for further replies.

jdespres

MIS
Aug 4, 1999
230
US
I would like to use my alias's I have created in .bashrc in my script's. What a good way to do this?
 
Hi

.bashrc is read only by interactive instances of [tt]bash[/tt]. In a script you have to include it manually :
Code:
source ~/.bashrc
[gray]# or[/gray]
. ~/.bashrc

Feherke.
 
hhhhmmmmmmm......

That worked!

But....

I just discovered that it doesn't work within a for loop...

Which was my problem all along.....
 
Doesn't bash take in account the ENV file ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi

PHV said:
Doesn't bash take in account the ENV file ?
ENV file ? I heard about ENV variable. That one is used by [tt]sh[/tt] and [tt]bash[/tt] runed as [tt]sh[/tt]. [tt]bash[/tt] uses the BASH_ENV variable in the same way : if the variable's value is the name of a file, that one will be executed when a non-interactive shell starts.

Feherke.
 
ENV file ? I heard about ENV variable
Sorry, I meant:
Doesn't bash take in account the $ENV file ?
 
Here's what I have....

#!/bin/sh

# Check Drives on all the media servers

source ~/.bashrc

for i in `awk '{print $3}' Solaris_Systems`
do
echo "********************* $i *********************"
$i /usr/openv/volmgr/bin/vmoprcmd
done

I don't think I can do this....

It was worth a try....
 
And what about using this ?
$i /usr/openv/volmgr/bin/vmoprcmd </dev/null

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
It doesn't work, because alias handling in the shell takes precedence over variable substitution.

if you eval then thus constructed command line, it will work.

Code:
eval $i /usr/openv/volmgr/bin/vmoprcmd


HTH,

p5wizard
 
I spoke too soon......

I'm attempting to run the following aliased string:

'ssh -tXC system1 "ssh -t -X -C system2 \"$@\""ssh -t -X -C system3 \"$@\"""'

Running the following as a alias with "uname -a" works:

"alias_command" uname -a

But when I attempt to use P5wizard's solution. It works for the nodes with 1 hop.... any thing else won't see any switches added. It will get the uname but won't get the "uname -a
 
Why so complicated? Why not just do one after the other rather than trying to hop from one to the other?

This is the evaluation sequence as best I can tell:

[tt]'ssh -tXC system1 "ssh -t -X -C system2 \"$@\""ssh -t -X -C system3 \"$@\"""'
ssh -tXC system1 "ssh -t -X -C system2 \"$@\""ssh -t -X -C system3 \"$@\"""
ssh -t -X -C system2 "uname -a"ssh -t -X -C system3 "uname -a"[/tt]

So it's probably trying to run a command uname -assh? Try separating those commands with a ";" before the third "ssh" perhaps?



Annihilannic.
 
What if you write a script that is available on all the nodes and which, depending on the value of the first parameter, will ssh-hop to the next node or ultimately run an aliased command line?

ssh -tXC system1 /usr/local/bin/sshop+alias system2 system3 - alias-cmd

content of sshop+alias could be something like:
#!/bin.bash
# # # # #
# source the .bashrc or do whatever else to install aliases
. ~/.bashrc
# if first parameter is a "-" then eval the command which follows
# otherwise, hop to next node
if [ "$1" = "-" ]
then
shift
eval $*
else
nextnode=$1
shift
ssh -tXC ${nextnode} /usr/local/bin/sshop+alias $*
fi


I don't use/know bash, but I guess shift is available. Anyway, hope you get the idea.


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top