bash: syntax error near unexpected token

Benjamin Kaplan benjamin.kaplan at case.edu
Mon Aug 16 23:40:42 EDT 2010


On Mon, Aug 16, 2010 at 11:33 PM, kreglet <kreglet at gmail.com> wrote:
> Hello,
>
> I started learning python last year. All of this time i have used the
> terminal and gedit to create, modify, and test my applications and modules.
> For some reason I can not do this any more.
> I'll try to do my best to explain whats happening.
>
> I have a script modtest.py which has a function to test if an int is even or
> odd.
>
> Before:
> desktop:~/bin$ modtest.py
> desktop:~/bin$ evenodd(45)
> 45 is odd
>

That never worked. You can execute Python scripts from the shell, but
not arbitrary Python functions. Perhaps you were calling Python using
the -i flag, which runs the interactive interpreter after the script
is finished executing.

$ python -i modtest.py
>>> evenodd(45)
45 is odd


> Now:
> desktop:~/bin$ modtest.py
> desktop:~/bin$ evenodd(45)
> bash: syntax error near unexpected token `45'
>

And this is what's supposed to happen any time you try this in any
shell. When you call evenodd, bash looks for a program or shell
built-in called evenodd. Which doesn't exist.

> The above is just an example. ALL of my scripts that worked before no longer
> work in the terminal yet they work in the python interpreter.
>
> Does anyone know what the problem might be and how I can fix it?
>
>



More information about the Python-list mailing list