Python code to replace shell scripts
William Park
opengeometry at yahoo.ca
Thu Dec 11 20:58:23 EST 2003
Daven Nair <nair_260 at hotmail.com> wrote:
> Hi,
>
> I would like to know if Python supports codes similar to shell scripts:
>
> count=`ps -ef|grep "pattern"|wc -l`
> for count in `echo $count`
> do
> done
> fi
>
> Can I export a variable say var from os.system("var=`ps -ef|grep pattern|wc
> -l`")
No. 'os.system()' will fork a subshell, and, as you know, subshell
cannot change parent's environment. Furthermore, your shell script is
not proper. It should go like
for count in `...`; do
...
done
In any case, although Python does something well, shell does most things
better. (It's okey... I've got my helmet on.)
--
William Park, Open Geometry Consulting, <opengeometry at yahoo.ca>
Linux solution for data management and processing.
More information about the Python-list
mailing list