help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Using <<-'EOF' with python


From: Pierre Gaston
Subject: Re: [Help-bash] Using <<-'EOF' with python
Date: Sun, 8 May 2016 20:38:24 +0300

bash removes all the leading TABs, so if you only use them, python doesn't
see any indentation

On Sun, May 8, 2016 at 8:12 PM, Peng Yu <address@hidden> wrote:

> This is strange. After I change the TABs to spaces, main.sh indeed works.
>
> But python should be able to accept TABs as shown the following
> example. So why TABs can not be used in `python <<-EOF`?
>
> ~$ cat -T < main1.py
> # vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1
> fileencoding=utf-8:
>
> for i in xrange(3):
> ^Iprint i
> ~$ python < main1.py
> 0
> 1
> 2
>
>
> On Sun, May 8, 2016 at 11:32 AM, Pierre Gaston <address@hidden>
> wrote:
> >
> >
> > On Sun, May 8, 2016 at 7:24 PM, Peng Yu <address@hidden> wrote:
> >>
> >> Hi,
> >>
> >> The following code shows that python may not work with <<-EOF
> >> correctly. Is there a way to only allow bash to eat the same number of
> >> spaces/tabs as the line where the python is being called.
> >>
> >> ~$ cat main.sh
> >> #!/usr/bin/env bash
> >> # vim: set noexpandtab tabstop=2:
> >>
> >> for x in a b c
> >> do
> >>     python <<-EOF
> >>     for i in xrange(3):
> >>         print i
> >>
> >>     EOF
> >> done
> >>
> >> ~$ ./main.sh
> >>   File "<stdin>", line 2
> >>     print i
> >>         ^
> >> IndentationError: expected an indented block
> >>   File "<stdin>", line 2
> >>     print i
> >>         ^
> >> IndentationError: expected an indented block
> >>   File "<stdin>", line 2
> >>     print i
> >>         ^
> >> IndentationError: expected an indented block
> >>
> >> --
> >> Regards,
> >> Peng
> >>
> > When you use <<-EOF it only eats the leading TAB characters.
> > if you indent the herecode with tabs and the python code with spaces it
> will
> > work.
> >
>
>
>
> --
> Regards,
> Peng
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]