1845913 Members
4447 Online
110250 Solutions
New Discussion

Alias In Shell Script

 
SOLVED
Go to solution
Ash_4
Advisor

Alias In Shell Script

Hi,
Can i user defined aliases in shell script.
When used it gives "not found"

Thanks.
12 REPLIES 12
Alan Casey
Trusted Contributor

Re: Alias In Shell Script

Try using the full path:
/usr/bin/alias
Leif Halvarsson_2
Honored Contributor

Re: Alias In Shell Script

Hi

I tested it, for some reason it did not work.
A simple workaround.

In the beginning of your script:

. $HOME/.kshrc

The "." in the beginning of the line is important.
Leif Halvarsson_2
Honored Contributor

Re: Alias In Shell Script

Hi
Note there is a space between the "." and the rest of the line.
Ash_4
Advisor

Re: Alias In Shell Script

Hi,
Still No success.
Robin Wakefield
Honored Contributor

Re: Alias In Shell Script

Hi,

Have you got a copy/snippet of the script?

Rgds, Robin
Leif Halvarsson_2
Honored Contributor

Re: Alias In Shell Script

Hi
Have you tried my "workaround". I have tested it and it works.
Ash_4
Advisor

Re: Alias In Shell Script

hi,

.kshrc
=======
alias frm="export ORACLE_HOME=/d2k/app/oracle7.2 PATH=$PATH:/d2k/app/oracle7.2/b
in TWO_TASK=FRS"

alias nfrm="export ORACLE_HOME=/data1/app/oracle/product/8.0.4 PATH=$PATH:/data
1/app/oracle/product/8.0.4/bin; unset TWO_TASK"

t.sh
=====
frm # defined alias
echo "$TWO_TASK"

nofrm #Defined alias
echo "$TWO_TASK"



Leif Halvarsson_2
Honored Contributor
Solution

Re: Alias In Shell Script

hi

t.sh
=====
. $HOME/.kshrc
frm # defined alias
echo "$TWO_TASK"

nofrm #Defined alias
echo "$TWO_TASK"

Ceesjan van Hattum
Esteemed Contributor

Re: Alias In Shell Script

Or just start your script with the first line like:

#!/usr/bin/ksh

This way it takes the .kshrc.

Regards,
Ceesjan
Ash_4
Advisor

Re: Alias In Shell Script

It worked Leif Halvarsson .
Thanks to all.
Deepak Extross
Honored Contributor

Re: Alias In Shell Script

Hi,

When calling up your script, invoke it in the current shell like so:
. t.sh

hope this helps.
Leif Halvarsson_2
Honored Contributor

Re: Alias In Shell Script

Hi

When defining alias in .kshrc, use the -x option (= exported alias).
Example:
alias -x dir=ls

Now the alias should work in scripts witout reading the .kshrc file in the script (the line:
. $HOME/.kshrc
is not necessary).