The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Accessing variables of one shell script in another shell script rsendhilmani Shell Programming and Scripting 2 03-17-2009 01:17 AM
Accessing PL/SQL OUT variables in Korn Shell Script bright_future UNIX for Advanced & Expert Users 4 12-02-2008 12:02 PM
Accessing variables of one shell script in another shell script looza Shell Programming and Scripting 2 06-30-2008 08:13 PM
Accessing the parameters of a shell script The Observer Shell Programming and Scripting 2 06-20-2008 10:09 AM
Accessing var from .profile into shell script videsh77 Shell Programming and Scripting 7 05-28-2005 01:21 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-17-2008
cooldude cooldude is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 44
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 (permalink)  
Old 07-17-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by cooldude View Post
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 (permalink)  
Old 07-18-2008
cooldude cooldude is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 44
Quote:
Originally Posted by cfajohnson View Post

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 (permalink)  
Old 07-18-2008
spirtle spirtle is offline
Registered User
  
 

Join Date: Jun 2008
Location: Scotland
Posts: 150
Quote:
os.system() invokes the the shell
It starts a shell, but not necessarily the shell where you defined your aliases.
  #5 (permalink)  
Old 07-18-2008
cooldude cooldude is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 44
How can I solve this problem? This seems as if this can happen in any language I use.
  #6 (permalink)  
Old 07-18-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by cooldude View Post
How can I solve this problem? This seems as if this can happen in any language I use.

Create a script file instead of an alias. Aliases are not exported to the environment.

  #7 (permalink)  
Old 07-18-2008
spirtle spirtle is offline
Registered User
  
 

Join Date: Jun 2008
Location: Scotland
Posts: 150
You cannot use alias in one shell if it is defined in another. This is independent of any programming language.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:36 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0