Syntax error

something strange, if i run my script like that :

$ /opt/local/bin/ruby myscript.rb

no prob

the shebang in my script is :

#!/usr/bin/env ruby -w

which ruby give me the above ruby (under /opt)

then, running this script as :

$ ./myscript.rb i get an error on line 8 :
./wav2xml.rb: line 8: syntax error near unexpected token (' ./wav2xml.rb: line 8: fxml=file.gsub(/(.*).wav/,’\1.xml’)’

the major difference is upon the “-w” option within the shebang however,
if i delete this option i do have the same error.

sometimes an error given at one line comes from the preceeding one :
file=RGV[0] # line 7

for me the syntax is correct ???

Une bévue wrote:

which ruby give me the above ruby (under /opt)

then, running this script as :

$ ./myscript.rb i get an error on line 8 :
./wav2xml.rb: line 8: syntax error near unexpected token (' ./wav2xml.rb: line 8: fxml=file.gsub(/(.*).wav/,’\1.xml’)’

the major difference is upon the “-w” option within the shebang however,
if i delete this option i do have the same error.

Show us the code that caused the error. It is obviously a real error,
but it
is difficult to sort out what it is from the message.

sometimes an error given at one line comes from the preceeding one :
file=RGV[0] # line 7

for me the syntax is correct ???

What is in RGV[0]? What is the content of the offending line?

Maybe you should change the shebang line you are using, or delete one of
the
ruby references on your system (you appear to have more than one).

Using the “/usr/bin/env ruby” shebang line makes an assumption about
your
system, that you will always hit the intended Ruby version first. If you
have more than one version installed, you may not hit the intended one,
depending on the order of your search path.

But this is speculation without seeing the error line and its context.

Paul L. [email protected] wrote:

Show us the code that caused the error. It is obviously a real error, but it
is difficult to sort out what it is from the message.

here is part of the script down to the line giving an error (line 8) :

#!/usr/bin/env ruby -w

if ARGV.length==1
xml=“”
found=false
root=“”
file=ARGV[0]
fxml=file.gsub(/(.*).wav/,‘\1.xml’) # *** LINE 8 ***
rgxstart=Regexp.new(“”)
rgxstop=Regexp.new(“”)
i=0
File.open(file).each { |l|
[…]
of=File.open(fxml, File::WRONLY|File::EXCL|File::CREAT, 0644)
of.puts xml
}
else
puts “File name missing.”
end

sometimes an error given at one line comes from the preceeding one :
file=RGV[0] # line 7

for me the syntax is correct ???

What is in RGV[0]? What is the content of the offending line?

RGV[0] is a typo of mine, it should be read :
ARGV[0]

Maybe you should change the shebang line you are using, or delete one of the
ruby references on your system (you appear to have more than one).
yes i do have three ruby versions installed on my box [Mac OS X Tiger
the latest] :

the default Apple’s one : /usr/bin/ruby # version 1.8.2
the MacPort installed : /opt/local/bin/ruby # version 1.8.5
the SVN-jRuby one : /Users/yvon/bin/jruby/bin/jruby # version 1.8.5 (0)
[java]

both MacPort and SVN-jRuby ones are working and cohabit nicely.

the Apple’s one doesn’t like (i think) the env vars i’ve setup for the
MacPort one (under /opt) here they are :

export RUBYOPT=rubygems
export GEM_HOME=/opt/local/lib/ruby/gems/1.8
export RUBYLIB=/opt/local/lib/ruby/:/opt/local/lib/ruby/site_ruby/1.8
export RUBYGEMS=/opt/local/lib/ruby/site_ruby/1.8

Using the “/usr/bin/env ruby” shebang line makes an assumption about your
system, that you will always hit the intended Ruby version first. If you
have more than one version installed, you may not hit the intended one,
depending on the order of your search path.

Yes a know that point, my PATH is such a way it hits first the ruby
version below /opt then, if i want to use the Apple’s one i have to do :
$ /usr/bin/ruby

notice i might change that using aliases as i’ve allready done to makes
Ruby and jRuby cohabit nicely :

every command for jRuby is the “same” as the Ruby one with the “prefix”
“j” :

gem install -o-> jgem install

then may be a solution would be to prefix the commands related to
Apple’s Ruby with an “a”.

i don’t want to install anything for the Apple’s version, i want to
leave it untouched.

But this is speculation without seeing the error line and its context.

it was given in the preceeding message, even the line before .

On Sat, 2006-11-25 at 16:40 +0900, Une bévue wrote:

which ruby give me the above ruby (under /opt)

then, running this script as :

$ ./myscript.rb i get an error on line 8 :
./wav2xml.rb: line 8: syntax error near unexpected token (' ./wav2xml.rb: line 8: fxml=file.gsub(/(.*).wav/,’\1.xml’)’

the major difference is upon the “-w” option within the shebang however,
if i delete this option i do have the same error.

The error you’re seeing isn’t from Ruby - it’s your shell trying to
interpret the ruby code. This problem has been encountered before, e.g:

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/76135

and FWIW it doesn’t work on my Linux either.

Ross B. [email protected] wrote:

The error you’re seeing isn’t from Ruby - it’s your shell trying to
interpret the ruby code. This problem has been encountered before, e.g:

  http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/76135

and FWIW it doesn’t work on my Linux either.

that’s really odd and new to me, i tell you i’m working with, at least
three versions of ruby on my box since 3 years and that’s, as far as I
remember well, the first time i get that…

something very tricky is the same script with the same shebang works
fine over another Apple’s box with only the default ruby installed…

the user said “Works fine !”

for the time being i don’t know the user’s Mac OS X version nor ruby
obviously.

i’m using that /usr/bin/ruby ONLY for testing purpose and this is the
testing which fails, not the script…

anyway thanks a lot for your ref.

i’ve to find a workaround…

Une bévue wrote:

xml=""
found=false
root=""
file=ARGV[0]
fxml=file.gsub(/(.*).wav/,’\1.xml’) # *** LINE 8 ***

Okay. I successfully ran your code this way:

file = “test.wav”

fxml=file.gsub(/(.*).wav/,’\1.xml’)

puts fxml

output:

test.xml

So there is nothing wrong with the syntax in the line creating the error
message.

I had hoped there was something important preceding the single code line
you
provided earlier, but this seems less likely now that I see it.

/ …

What is in RGV[0]? What is the content of the offending line?

RGV[0] is a typo of mine, it should be read :
ARGV[0]

Please do not retype your code into the newsreader. Instead, copy it
directly from your programming editor. This may be the problem – the
code
in your programming editor may not be identical to the code you have
posted, because the code you posted runs fine.

/ …

But this is speculation without seeing the error line and its context.

it was given in the preceeding message, even the line before .

In your first post, you only provdied the single error line (no
context).
Now that I have seen the context and run a test I see there is nothing
wrong with the code that produces the error message. But there are still
the issues that (1) you apparently typed your code into the newsreader
instead of copying it, and (2) you have three Ruby versions installed.

If (1) the code you are running is identical to the code you posted, and
(2)
you are still getting the error message, then (3) you have to get rid of
two of the three Ruby versions that are now living on your system.

both MacPort and SVN-jRuby ones are working and cohabit nicely.

Except that your system will not execute perfectly good code, which
means
the three Ruby versions are not cohabiting nicely – unless you are
typing
your code instead of copying it.

Paul L. [email protected] wrote:

test.xml

So there is nothing wrong with the syntax in the line creating the error
message.

OK then we agree…

What is in RGV[0]? What is the content of the offending line?

RGV[0] is a typo of mine, it should be read :
ARGV[0]

Please do not retype your code into the newsreader. Instead, copy it
directly from your programming editor.

Unfortunately i can’t anymore, because, on MacOS X, using “System
Events.app” i did something wrong (?) and cut’n paste and drag’n drop
facilities disappeared…

That only in my account if i add another one, for this new account,
cut’n paste and drag’n drop are working as expected…

This may be the problem – the code
in your programming editor may not be identical to the code you have
posted, because the code you posted runs fine.

yes my code works fine even on another computer which i don’t know the
OS version nor the ruby version.

someone gave me (other thread in this group if interested see message
76135, 76138 and 76139 on ruby-talk) it seems to be related to the
shebang i use :

#!/usr/bin/env ruby # [with or without -w]

the args given to a ruby script are miss-interpreted by the SHELL.

I’ve discovered that today althought i’m using ruby at least since 3
years…

and i’m more or less obliged to use this kind of shebang because the
users i’ve use /usr/bin/ruby for ruby where i use /opt/local/bin/ruby, i
don’t want to change anything – even the shebang – between my version
and the version for the users…

the issues that (1) you apparently typed your code into the newsreader
instead of copying it, and (2) you have three Ruby versions installed.

If (1) the code you are running is identical to the code you posted, and (2)
you are still getting the error message, then (3) you have to get rid of
two of the three Ruby versions that are now living on your system.

NO definitely NO the first version is the one used by Apple’s OS i don’t
want to touch it.

then i need at least a second version to play with gems.

the second is mine installed in a proper way by MacPort, this is the one
i’m using generally.

the third is devoted to jRuby and doesn’t interfere by anyway with the
others because first it isn’t in the PATH, second it’s under my HOME,
third it is a somehow “special” ruby for jRuby (ruby 1.8.5 (0) [java])
and lastly the executable files aren’t root:admin as owner:group rather
than yvon;yvon.

MacOS X claimed to be a Unix OS then this MUST cohabite nicely.

both MacPort and SVN-jRuby ones are working and cohabit nicely.

Except that your system will not execute perfectly good code, which means
the three Ruby versions are not cohabiting nicely – unless you are typing
your code instead of copying it.

not all the prob, i’ve discovered that this morning comes from Apple’s
itself since years (2 to 3) and it’s really odd.

Une bévue wrote:

output:

test.xml

So there is nothing wrong with the syntax in the line creating the error
message.

OK then we agree…

We agree that the line should not have produced an error. We apparently
don’t agree that your setup (multiple Ruby versions and no clear way to
distinguish between them) caused the problem.

facilities disappeared…
Re-install Mac OS X if you have to. Not being able to post your code as
written is very serious. Not being able to cut and paste is even more
serious.

That only in my account if i add another one, for this new account,
cut’n paste and drag’n drop are working as expected…

Then the problem is limited to your user space. Remedy: back up all your
user files, delete your user account, reestablish it, restore your
backed-up files.

This may be the problem – the code
in your programming editor may not be identical to the code you have
posted, because the code you posted runs fine.

yes my code works fine even on another computer which i don’t know the
OS version nor the ruby version.

Okay. Two facts:

  1. Your code doesn’t work on your machine, but it works on another
    machine
    just fine.

  2. The way you have of installing and using multiple Ruby versions is
    “no
    prob”.

One of these facts isn’t a fact.

someone gave me (other thread in this group if interested see message
76135, 76138 and 76139 on ruby-talk) it seems to be related to the
shebang i use :

#!/usr/bin/env ruby # [with or without -w]

the args given to a ruby script are miss-interpreted by the SHELL.

So don’t do this any more. Instead, create a symlink located
at /usr/local/bin/ruby. Change this symlink when you want to change Ruby
versions.

I’ve discovered that today althought i’m using ruby at least since 3
years…

and i’m more or less obliged to use this kind of shebang because the
users

No, you are not obliged to do this. You can edit your scripts before
delivery. Or you can make rewrite /usr/bin/env to do something special
for
you WRT Ruby (a less attractive solution).

i’ve use /usr/bin/ruby for ruby where i use /opt/local/bin/ruby, i
don’t want to change anything – even the shebang – between my version
and the version for the users…

  1. Change your scripts to all refer to /usr/local/bin/ruby.
  2. Change your system/user search path to have /usr/local/bin as the
    first
    search entry.
  3. Put a symlink at /usr/local/bin/ruby, change it as required.
  4. Don’t use environmental variables.
  5. Don’t use aliases.
  6. Use a Ruby script to edit your scripts, before delivery to your
    clients,
    that changes /usr/local/bin/ruby to whatever the client needs to have
    there.

Alternative: create your own version of /usr/bin/env that doesn’t mess
up
the search for Ruby.

/ …

If (1) the code you are running is identical to the code you posted, and
(2) you are still getting the error message, then (3) you have to get rid
of two of the three Ruby versions that are now living on your system.

NO definitely NO the first version is the one used by Apple’s OS i don’t
want to touch it.

Okay, then. Use a symlink. And hope that these various Ruby versions are
not
writing to the same library locations.

then i need at least a second version to play with gems.

the second is mine installed in a proper way by MacPort, this is the one
i’m using generally.

the third is devoted to jRuby and doesn’t interfere by anyway with the
others because first it isn’t in the PATH, second it’s under my HOME,
third it is a somehow “special” ruby for jRuby (ruby 1.8.5 (0) [java])
and lastly the executable files aren’t root:admin as owner:group rather
than yvon;yvon.

Your argument seems to be:

  1. “I must have multiple Ruby versions.”

  2. “I can’t get my scripts to work.”

  3. “Help!”

As Americans say, something has to give.

/ …

Except that your system will not execute perfectly good code, which means
the three Ruby versions are not cohabiting nicely – unless you are
typing your code instead of copying it.

not all the prob, i’ve discovered that this morning comes from Apple’s
itself since years (2 to 3) and it’s really odd.

The fact is that perfectly good code raised an error message, and you do
not
know why. The error in /usr/bin/env can’t cause good Ruby code to
produce
an error, because it would have selected a Ruby version, and no Ruby
version would have rejeted the line you posted.

Re-reading … What? You are saying that the Apple Ruby version is the
source of the error? So remove that version of Ruby from your system.
Update it, delete it, whatever.

Don’t you realize that this error-prone Ruby version (if this is what
you
are saying) may have hundreds of other surprises for you? That this will
make it impossible to develop code that can be expected to work reliably
anywhere?

Paul L. [email protected] wrote:

That only in my account if i add another one, for this new account,
cut’n paste and drag’n drop are working as expected…

Then the problem is limited to your user space. Remedy: back up all your
user files, delete your user account, reestablish it, restore your
backed-up files.

NO i won’t do that why ?

Because it arroses two times , i tell you :

the first time this prob aroses, i’ve made what you have writen above
even more :

  • backup everything into a firewire disk
  • backup personal datas to my .Mac account
  • erase my main hard disk setting all the datas to zero.
  • reinstall from scratch Mac OS X + Dev Tools + Java + Updates

(one half day time)

then i said : “why not looking on file perms using disk utility ?”

you can’t believe it BUT it is true with this clean-fresh-and-new
install done ONLY with package coming from Apple, disk utility reported
me a bunch of faulty perms/owner, the file size (still on my desktop)
speaks by itself :

**** 14.7 MB ****

that was last saturday the 18th.

then on monday i continue to work on my box, i had to finished the
faulty AppleScript (nothing to do with ruby here), my mistake was to use
a reserved word “count” as index…

obviously i didn’t make the same mistake two times )))

but cut’n and paste desapeared a second time last monday eve’

that’s the reason why i don’t want to wipe my actual account, build
another etc…

i do agree it would be the shortest solution to cure that really odd
prob.

BUT, if i do that, i don’t learn what is the exact cause of the prob and
what is the file causing such a bad behaviour.

then for the time being, i use my box as it is and, from time to time i
look for solving this prob, in hope i could find the faulty file and/or
setup…

On 2006-11-25, Une bévue [email protected] wrote:

Unfortunately i can’t anymore, because, on MacOS X, using “System
Events.app” i did something wrong (?) and cut’n paste and drag’n drop
facilities disappeared…

Rather than copy/paste with the UI, can’t you save the code in question
to
a file and use your newsreader’s “insert file” (or whatever it’s called)
facility to insert the code into your message?

Jim C. [email protected] wrote:

Rather than copy/paste with the UI, can’t you save the code in question to
a file and use your newsreader’s “insert file” (or whatever it’s called)
facility to insert the code into your message?

Nope :wink:

With the news reader i’m using : MacSOUP (on MacOS X)

but you’re right in such a situation i would hve better to use another
nes reader.

The reason i’m still using MacSOUP is because of it’s way to represent
thread, very usefull tome.

See this screenshot :

http://thoraval.yvon.free.fr/Audio/MacSOUP.png