Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: bash: syntax error near unexpected token

Reply
Thread Tools

Re: bash: syntax error near unexpected token

 
 
Benjamin Kaplan
Guest
Posts: n/a
 
      08-17-2010
On Mon, Aug 16, 2010 at 11:33 PM, kreglet <(E-Mail Removed)> 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?
>
>

 
Reply With Quote
 
 
 
 
Hans Mulder
Guest
Posts: n/a
 
      08-17-2010
Benjamin Kaplan wrote:
> On Mon, Aug 16, 2010 at 11:33 PM, kreglet <(E-Mail Removed)> wrote:


>> 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.


That's not what "syntax error means". If the problem were that
evenodd does not exist as a shell function, the error would have
been "bash: evenodd: command not found".

I do not understand why bash says the token `45' is unexpected.
The '(' token is the problem. It's a syntax error because in
bash syntax function arguments are not enclosed in parentheses:

$ function evenodd {
> if (( $1 % 2 ))
> then echo $1 is odd
> else echo $1 is even
> fi
> }

$ evenodd 45
45 is odd
$ evenodd(45)
bash: syntax error near unexpected token `45'
$

Of course, this is completely off-topic.

-- HansM
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
library IEEE_PROPOSED: how compile it? ERROR: syntax error near .... (VHDL-1261) ducatired VHDL 2 01-17-2008 01:15 PM
This is an unexpected token. The expected token is 'NAME' =?Utf-8?B?Y2FzaGRlc2ttYWM=?= ASP .Net 2 07-13-2007 11:38 AM
syntax error near unexpected token `TO_CHAR(L' aemi Java 2 03-02-2007 06:31 AM
syntax error near unexpected token bernard_reims@hotmail.fr Perl Misc 11 01-19-2006 07:21 AM
syntax error near unexpected token `<bigaf>' - AIX C++ Application Porting from 32 bit to 64 bit r.nikhilk@gmail.com C++ 5 12-01-2005 08:03 PM



Advertisments