0

I have this at the top of my file:

#!/usr/bin/env ruby -s

It works without the -s and runs correctly however I want easy switches so I want -s to work. When I run it with -s I get:

/usr/bin/env: ruby -s: No such file or directory

Is this a syntax error?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
isignisign
  • 541
  • 2
  • 4
  • 13

1 Answers1

2

You can only pass a single option to the command named in in the shebang line. Or truly spoken, if you pass multiple arguments, they will not get exploded but passed as single argument. In this case like:

/usr/bin/env 'ruby -s'

But the file 'ruby -s' does not exist. That's why the error message.

Following the Ruby's man page, you are supposed do use the following shebang:

#! /usr/bin/ruby -s
# :prints "true" if invoked with `-xyz' switch.
print "true\n" if $xyz

You need to call ruby directly instead of using /usr/bin/env. This is a drawback, but doing so, you can call the script like this:

./script.rb -xyz
hek2mgl
  • 152,036
  • 28
  • 249
  • 266