Accessing aliases within a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Accessing aliases within a shell script
# 1  
Old 07-17-2008
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 script should run other user's environments. My script allows me to run commands passed in as arguments, which include aliases to programs, so I can't hardcode any alias values in the program. For example, "myscript grep" would run grep by using os.system() in myscript.
Help would be appreciated.

Thanks.
# 2  
Old 07-17-2008
Quote:
Originally Posted by cooldude
I am not able to access the aliases in my environment within a Python script.

Aliases are shell constructs; they have to be expanded by the shell. Other languages have no knowledge of them (or have their own aliases).
# 3  
Old 07-18-2008
Quote:
Originally Posted by cfajohnson

Aliases are shell constructs; they have to be expanded by the shell. Other languages have no knowledge of them (or have their own aliases).
They are shell constructs, but os.system() invokes the the shell. It is no different than the system() call in Unix. In fact, it probably calls system. That's why I see "sh: x: not found"
# 4  
Old 07-18-2008
Quote:
os.system() invokes the the shell
It starts a shell, but not necessarily the shell where you defined your aliases.
# 5  
Old 07-18-2008
How can I solve this problem? This seems as if this can happen in any language I use.
# 6  
Old 07-18-2008
You cannot use alias in one shell if it is defined in another. This is independent of any programming language.
# 7  
Old 07-18-2008
Is there a way to send the command to the shell where the script is being executed?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 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. UNIX for Advanced & Expert Users

Accessing secured server using shell script

Hi, I was trying to connect secure server using SFTP, but end up in error. Im looking for a shell script which will connect my secured FTP server For EG: hostname = example.com username = fed password = pass port = 993 Destination = web Push some tar file into web folder which is in... (3 Replies)
Discussion started by: Paulwintech
3 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 variables of one shell script in another shell script

Hi All, I have a shell script called sample1.sh where I have 2 variables. Now I have another shell script called sample2.sh. I want the variables in sample1.sh to be available to sample2.sh. For example. In sample1.sh I am finding the sum of 2 numbers namely a and b. Now I want to access... (2 Replies)
Discussion started by: rsendhilmani
2 Replies

6. Shell Programming and Scripting

Accessing variables of one shell script in another shell script

I have a variable $exe in a shell script file a.sh which I need to access in another shell script file b.sh. How can I do that? :rolleyes: Thanks!! (2 Replies)
Discussion started by: looza
2 Replies

7. Shell Programming and Scripting

Accessing the parameters of a shell script

Hi, I have one situation. I am developing a shell script to which parameters will be passed from a Web based User Interface using some Business Process(BP).There are some 6 parameters for which user will enter the values in UI. These values will be passed to script by BP in the form -... (2 Replies)
Discussion started by: The Observer
2 Replies

8. UNIX for Dummies Questions & Answers

accessing shell script variable in file

Hi, I have a shell script in which there is a file conn_$temp where $temp has the pid of the shell script. in this shell script i have an embedded awk script that must read the file while ((getline < "conn_$temp") > 0) However due to the "$temp" in the file name, the awk script is... (6 Replies)
Discussion started by: HIMANI
6 Replies

9. Shell Programming and Scripting

Accessing var from .profile into shell script

I have defined variable in .profile file. This variable, I tried to use in a shell script for the same session. In Shell script it is not finding this variable, but the same variable on the console if I try to access by echo $var, it is giving me correct assigned value. Can anyone, please... (7 Replies)
Discussion started by: videsh77
7 Replies

10. Solaris

Accessing the home directory in shell script

How can I access home directory in a shell script. I am writing a script which will delete the log files in each of the user's directory Krishan (1 Reply)
Discussion started by: krishan
1 Replies
Login or Register to Ask a Question