os.popen('alias')

Chris F.A. Johnson cfajohnson at gmail.com
Sat Nov 19 07:04:51 CET 2005


On 2005-11-19, Chris F.A. Johnson wrote:
> On 2005-11-18, Belebele wrote:
>>>From an interactive python shell, I execute the following:
>>
>>                 import os
>>                 for line in os.popen('alias').readlines():
>>                           print line
>>
>>
>> No aliases are printed.
>>
>> I started python from an bash environment that had many aliases
>> defined. I expected to see the list of aliases from within the
>> interactive python shell.
>
>     Since bash does not export aliases, they cannot be seen by a child
>     process.
>
>> What could I do to see those aliases defined in the shell from where
>> I started python?
>
>     Store them in a file before calling python, and read that file.

   Or redefine them as functions and use:

import os
for line in os.popen('typeset -f').readlines():
      print line

-- 
   Chris F.A. Johnson, author   |    <http://cfaj.freeshell.org>
   Shell Scripting Recipes:     |  My code in this post, if any,
   A Problem-Solution Approach  |          is released under the
   2005, Apress                 |     GNU General Public Licence



More information about the Python-list mailing list