Can we use aliased commands in script?

Hi All,
I need a small help.. when we use aliased commands in shell script, they are not being recognized when I used. Is there any way to use aliased commands in scritping? Please let me know if u know...

Thank you
Chanu

you need to load your alias' available in your .profile to the script that is run

# !/usr/bin/ksh

. $HOME/.profile

<check_with_your_alias>
<ideally_should_work>

exit 0

Thanks for that but my question is can we use the aliased commands in our script... for example

in $HOME/.bashrc it is defined as

alias h='history'

and in one of the shell scripts if "h" is used, it is an error.. is there any way to use aliased commands in our scripts or it is not possible at all...

deleted.............

Now i will explain u in detail..

in my .bashrc i alised getip1, getip2, getip3 and my script is simple command

getip$*

save with name "getip".

when i run the script as getip 1 2 3 expected output is it has to run getip1, getip2 and getip3 but error is "getip1: command not found" ..

After ur suggestion i changed the script to

. $HOME/.bashrc
getip$*

even then same error.. do needful...ok

include the line #!/usr/bin/ksh as your first line in the script, it will work

even now it is not working...

$ more pf
alias hello="echo"

$ more t1.sh
#!/usr/bin/ksh

. ./pf

hello Hai

$ t1.sh
Hai

It is working absolutely fine for me, could you please post your full code here if still not working

What u sent is perfectly working.. but if the same thing is aliased in
$HOME/.bashrc file then it is not working...even i include . $HOME/.bashrc it is not working.. you also please try by aliasing in .bashrc file and let me know.. thank you

-Chanakya

$ ps
PID TTY TIME CMD
26025 pts/2 0:01 ksh
13901 pts/2 0:00 bash

$ more $HOME/.bashrc
alias hello="echo"

$ more t1.sh
#!/usr/bin/ksh

. $HOME/.bashrc

hello Hai

$ t1.sh
Hai

I have no idea what you are trying there, it works absolutly fine for me in all possible ways, in bash shell or in ksh shell....

can you post your .bashrc file and you complete shell script code..

let me explain u what i am trying here..

$more pf
alias ech1="echo"
alias ech2="echo"
alias ech3="echo"

$more t1.sh
#!/usr/bin/ksh

. $HOME/bin/pf

ech$* DONE

when i run the script with arguments 1 2 3

Expected ouput is
DONE
DONE
DONE

but current output is

t1.sh: line 5: ech1: command not found

one more this if i run the code for reloading file t1.sh from command prompt.. then i am able to use ech1 or ech2 or ech3..

i.e
$. ./pf
$ech1 DONE
DONE ***** This is output what i expected *****

Please do the same there and let me know the result...

sorry to miss this in earlier post... i have missed some of ur requirements...

Just say

eval ech${1} DONE

my requirement is i will supply a set of arguments like 1 2 3 etc...

what i understood is i need to use

eval ech${1} in place of ech$*... i tried this but it has not worked... please correct my code and send me..ok thanks in advance..

$ more pf
alias ech1="echo"
alias ech2="echo"
alias ech3="echo"

$ more t1.sh
#!/usr/bin/ksh

. $HOME/pf

eval ech$* DONE

$ t1.sh 1 2
2 DONE

still it works... no problem for me

Than you very much for ur help... Thanks a lot

Some where i read that if we use $* in the script the that will be applicable for all the arguments individually... i.e in our case if we give

t1.sh 1 2

my intension is it has to execute like

ech1 DONE
ech2 DONE.. but this is not happening...can u guide me in this aspect...

Thanks a lot mahendra..

now i am able to meet my requirements with for loop ... but one small doubt.. the script is working fine with out any errors only iff first liune of script is

"#!/usr/bin/ksh"..

it is not working if i use

"#!/usr/bin/bash"

... can u please fine time explain me the reason..

reason could be that u could be using solaris.. not linux.. is that so?

I bliv you need to use the alias -x. This is an exported alias, which is exported to all shells and sub shells. try using alias -x, but again I am not sure if all shells support the -x flag.

alias with -x option is not working...

Bourne...
How can we know whether it is solaris or linux..

use the command uname. for details use uname -a
dunno if the model command works on solaris, try that as well. it gives more detailed hardware specd of the server. it works with HP-UX, not sure bt solaris tho.