[Tutor] spitshell for python
Alan Gauld
alan.gauld at blueyonder.co.uk
Fri Sep 3 09:17:09 CEST 2004
> I don't think so. Typically there's a commonly accepted way to
> provide code that is legal under the shell and the language that
> will be ignored by python, but cause the shell to exec python
> with appropriate arguments. As an example, this works as the
> first lines in a perl script:
That doesn't help me I'm afraid. You are going to have to
explain what's happening in the perl code
> #!/usr/local/bin/perl
This bit I understand - it runs the perl interpreter :-)
> eval ' exec /usr/local/bin/perl -S $0 ${1+"$@"}'
And this evaluates a string as a perl instruction, or is
it as a shell instruction? hmm probably the latter.
But what is inside the string? It looks like we are
running another copy of perl to execute whatever
the $0... arguments are? What is the -S option?
> if $running_under_some_shell;
And I assume this is a conditional that determines
whether the eval gets executed depending on the shell,
ie Bourne, Bash, csh etc?
So I'm guessing that what you want is a bit of Python
code that will figure out which shell is running and
execute a shell command in that dialect?
And the bit of shell to execute, in turn, runs some
python script?
Am I right? If so that sounds like it brings me back
to execfile... so presumably I'm missing some magic
in the line noise at the end of the eval statement...
Alan G.
More information about the Tutor
mailing list