Are aliases available in shell scripts?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Are aliases available in shell scripts?
# 1  
Old 04-17-2013
Are aliases available in shell scripts?

I define aliases and save in rc file. what I see is that it isn't available in shell scripts. They are however available in interpretive or interactive sub-shell which I get when I give command
Code:
bash

For ex.:
Code:
I define 
alias echo='echo -n'

it's unavailable in shell scripts but sub-shells.
# 2  
Old 04-17-2013
Hi
I suppose you're using an interactive bash shell, and you have modified the .bashrc, can you try to disconnect and reconnect to the Unix environment?
# 3  
Old 04-17-2013
rc file gets sourced whenever user gets into a sub-shell, and hence the aliases gets reflected in sub-shell. This is not the case for shell script. To get the aliases inside the shell script, you need to source your file containing the aliases manually.

Guru.
# 4  
Old 04-17-2013
Guru, how to do manually ? and also please elaborate on your points so that it is clear
# 5  
Old 04-17-2013
To make your aliases work inside shell script, add a line like this in the beginning of your shell script:

Code:
source .bashrc #Assuming your shell is bash and rc file is .bashrc

Guru.
# 6  
Old 04-17-2013
Most shells do not support aliases inside shell scripts.

Aliasing echo into something else is a bad idea. If you want 'echo -n' all the time, use a command that supports \n in the first place, like printf, instead of redefining the universe.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Aliases NOT working inside bash shell script

i have defined a function ln_s() for customizing the ln command in script1.sh. more script1.sh echo "Starting Execution" ./script2.sh echo "End of Execution" ln_s(){ ] && return ln -s "$1" "$2" } My script1.sh executes another script2.sh which has the following entry more script2.sh... (12 Replies)
Discussion started by: mohtashims
12 Replies

2. Shell Programming and Scripting

Initialize aliases during shell script execution

Hello, I am trying to run a shell script that tests the connectivity to all the sftp servers and email if any one of them is down. There are aliases for all the servers with sftp command prefix in a '.alias' file. But when I use the alias name to run it as a command in my shell script to test... (3 Replies)
Discussion started by: Dippu
3 Replies

3. Shell Programming and Scripting

calling 'n' number of shell scripts based on dependency in one shell script.

Hello gurus, I have three korn shell script 3.1, 3.2, 3.3. I would like to call three shell script in one shell script. i m looking for something like this call 3.1; If 3.1 = "complete" then call 3.2; if 3.2 = ''COMPlete" then call 3.3; else exit The... (1 Reply)
Discussion started by: shashi369
1 Replies

4. Shell Programming and Scripting

execution of aliases from shell script

Hi I have to execute the commands in .aliases file from a shell script I tried 1.giving the alias directly in shell script 2.Giving the actually "value of alias" in the shell script 3. I tried giving both steps 1 and 2 inside ` quotes Still nothing is working . It says command... (3 Replies)
Discussion started by: ssuresh1999
3 Replies

5. Shell Programming and Scripting

Accessing aliases within a shell script

I am not able to access the aliases in my environment within a Python script. If I pass the alias to os.system(), I get a message saying "sh: x: not found". I've tried sourcing my .bashrc file in the script, but this does not work. I would perfer not to source my or any rc file because this... (9 Replies)
Discussion started by: cooldude
9 Replies

6. HP-UX

Shell Scripts

I have a text file . Format of text file. djss:xd:78:isdev:"test server" this type of row. (approx 30). I want to display like that 1. djjs@msxd testserver 2. xjfd@msxd devserver 3. 4 select any one from above choice : 1... (5 Replies)
Discussion started by: rastogideepak
5 Replies

7. Shell Programming and Scripting

Need Help With Shell scripts

Hello, I'm very very fresh with unix, and I would like to get familiar with it. I want to know what is Shell scripting and how other programming languages connects with it. And is there any way to learn the shell scripting, with some book and some simulator to practice on. Thanks ahead. (2 Replies)
Discussion started by: holler1
2 Replies

8. AIX

Difference between writing Unix Shell script and AIX Shell Scripts

Hi, Please give me the detailed Differences between writing Unix Shell script and AIX Shell Scripts. Thanks in advance..... (0 Replies)
Discussion started by: haroonec
0 Replies

9. Shell Programming and Scripting

shell scripts help

Hi, I am not experienced in shell scripts, I hope someone can give some hint for the following problem I have html file like this <html> <body> Some stuff More stuff <pre> A B </pre> Still more stuff And more <pre> C D </pre> Additional stuff </body> (2 Replies)
Discussion started by: ccp
2 Replies
Login or Register to Ask a Question