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

Re: wrapper script issue



Ken Irving wrote:
On Fri, Feb 08, 2008 at 02:02:30PM -0700, ChadDavis wrote:
First of all, I have wrapped my ruby binary in wrapper script as just indicated. the wrapper script is called "ruby1.8" and here's the contents:

#!/bin/sh
export RUBYOPT=rubygems
exec /etc/alternatives/ruby1.8 "$@"

Do you really want to quote the argument list?

Yes, he does.  If the wrapper is run as:

  ruby1.8 myscript "this is a test" 'a variable named $one'

The arguments need to be passed 'as is' to the script. Without the quotes, both $@ and $* present the full argument list, _without_ any quoting:

  this is a test a variable named $one

Which means at least 8 arguments, one of which is a variable that may now expand into nothing, or another list of one or more items.

Quoting $* passes a single long argument, which is what I think you're thinking of:

  "this is a test a variable named $one"

In this case, one long argument, with the $one being expanded.

Quoting $@ passes the arguments _with the same quoting as used originally_, so:

  ruby1.8 myscript "this is a test" 'a variable named $one'

executes:

  /etc/.../ruby1.8 myscript "this is a test" 'a variable named $one'

Which is exactly what is needed with a wrapper. Two arguments and $one is left alone.


I'm trying to execute the following ruby script, matz.rb

#!/usr/bin/ruby1.8
puts "Hello, Matz!"

Not likely the problem, but I'd suggest putting your wrapper into
/usr/local/bin/, or somewhere other than /usr/bin/, so that it doesn't
risk colliding with packaged software.  I have a /usr/bin/ruby1.8
on my system, and it's clearly not your wrapper.  Or maybe I'm just
misunderstanding something...

If I execute this script with explicit command line use of the ruby wrapper
script, such as:

me@myhost:~/temp/rubyTest$ ruby1.8 matz.rb

everything works fine!

My guess is that it would not work if matz.rb was given an argument, since
it would then look like
    me@myhost:~/temp/rubyTest$ ruby1.8 "matz.rb arg".

Actually, putting arguments in made no difference when I tried it, the puts worked in the one case and not the other.

  ruby1.8 matz.rb arg

Printed the string and seems to ignore the argument value.


The problem arises when I try to take advantage of the shebang notation to invoke
the ruby script with out explicit command line invocation of the ruby binary,
ala:

me@myhost:~/temp/rubyTest$ matz.rb

results in:

./matz.rb: line 2: puts: command not found

What am I missing here?

I don't know, but would suggest adding some simple debug statements
to your wrapper and other scripts to check and make sure you're doing
what you think you're doing.


Breaking down the processing being done may help.  You type:

  $ matz.rb

Which then becomes:

    /usr/bin/ruby1.8 /path/to/script/matz.rb

The question then is, what is /usr/bin/ruby1.8? On my system, it looks like the binary ruby executable (with ruby set up as a symlink to it).

So, what is the file /etc/alternatives/ruby1.8? Everything in /etc/alternatives on my system (except for README) is a symlink pointing back to /usr/bin/... or /usr/share/man/.../... or ...

So, I guess the questions are:

1. Do you have a /usr/bin/ruby1.8 and is it a binary file (about 3336 bytes)?

2.  Does /etc/alternatives/ruby1.8 exist and what type of file is it?

3.  Where is your wrapper script ruby1.8 located?

4. And, if both the wrapper ruby1.8 and /usr/bin/ruby1.8 exist, in different places, and your wrapper is executable, which of the two is being found in the PATH search?

--
Bob McGowan
Symantec, Inc.

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


Reply to: