[Tutor] Shell scripting

Chris Fuller cfuller084 at thinkingplanet.net
Wed Sep 17 20:45:48 CEST 2008


If you want the return code, there are at least two ways to do it.  My zsh 
shell is configured to print the last return code in the prompt:
0 % python
Python 2.4.4 (#2, Apr 15 2008, 23:43:20)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.exit(-1)
255 % python
Python 2.4.4 (#2, Apr 15 2008, 23:43:20)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> raise SystemExit(-1)
255 %

note that you are limited to eight bit integers.

To get some text, the usual backquote method for grabbing the output from a 
command to use in your script would work.  You should consult a bash manual 
for that, I use it so infrequently that I have to relearn it every time :)

Cheers

On Wednesday 17 September 2008 11:30, Patrick wrote:
> I was just wondering if there was a way to return the results of a
> python script to the bash shell? I was thinking about using the output
> as an argumen for another shell command. I know that we can use the
> shell from within Python via the OS module but I believe this is usually
> used to feed input into the program.
>
> Here is a silly pseudo code example:
>
> bash command | some-python-script.py |  some.other-script.sh
>
> thanks in advance-Patrick
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list