Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: mg Newsgroups: comp.lang.python Subject: Re: Embedding Python in a shell script Date: Fri, 17 Jun 2011 08:58:37 +0000 (UTC) Organization: Aioe.org NNTP Server Lines: 45 Message-ID: References: <3206787a-4feb-4098-8ed3-9e0b86ee7b57@o10g2000prn.googlegroups.com> NNTP-Posting-Host: l5NyLaDLfqw4AdEKvc4N1A.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: tin/1.9.6-20100522 ("Lochruan") (UNIX) (Linux/2.6.39 (x86_64)) X-Notice: Filtered by postfilter v. 0.8.2 Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7814 rusi wrote: > On Jun 17, 6:05 am, Chris Angelico wrote: > >> > Python call becomes.  I'd prefer something like: >> >> #!/bin/bash >> for i in 1 2 3 4; do >>   python -c "if True: > # comfortably indented python code > > Thanks. Nice! You can use bash here document feature, <<-, that strips heading tab characters but not spaces. #!/bin/bash for i in 1 2 3 4; do python /dev/stdin <<-EOF for i in range($i): print i # two tabs and four spaces EOF done Or alternatively you can use a temporary file: #!/bin/bash TEMPFILE=$(mktemp) trap 'rm -f $TEMPFILE' TERM INT cat > $TEMPFILE <