syntax error

U

Une bévue

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 ???
 
U

Une bévue

Paul Lutus said:
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("<BWFXML>")
rgxstop=Regexp.new("</BWFXML>")
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 <what u want> -o-> jgem install <what u want>

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

Ross Bamford

something strange, if i run my script like that :
=20
$ /opt/local/bin/ruby myscript.rb
=20
no prob
=20
the shebang in my script is :
=20
#!/usr/bin/env ruby -w
=20
which ruby give me the above ruby (under /opt)
=20
then, running this script as :
=20
$ ./myscript.rb i get an error on line 8 :
./wav2xml.rb: line 8: syntax error near unexpected token `('
./wav2xml.rb: line 8: ` fxml=3Dfile.gsub(/(.*)\.wav/,'\1.xml')'
=20
the major difference is upon the "-w" option within the shebang however,
if i delete this option i do have the same error.
=20

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

--=20
Ross Bamford - (e-mail address removed)
 
U

Une bévue

Ross Bamford said:
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...
 
U

Une bévue

Paul Lutus said:
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.

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


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.

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

Une bévue

Paul Lutus said:
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...
 
J

Jim Cochrane

Paul Lutus said:
...
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...

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?
 
U

Une bévue

Jim Cochrane said:
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 ;-)

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top