# Env command

**URL:** <https://www.ruby-forum.com/t/env-command/127927>\
**Category:** Ruby\
**Created:** [February 2, 2008, 6:59pm UTC](https://www.ruby-forum.com/t/env-command/127927 "2008-02-02T18:59:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![croese](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/839c29/32.png) [@croese](https://www.ruby-forum.com/u/croese)\
**Post date:** [February 2, 2008, 6:59pm UTC](https://www.ruby-forum.com/t/env-command/127927/1 "2008-02-02T18:59:15Z")

</div>

Does anyone know why I can type this at the cmd line:

/usr/bin/env ruby -w

and get the correct functionality, but if I use this line in the shebang  
line of my .rb files, I get an error from env stating that “ruby -w  
can’t be  
found”? If I change the line to use just ruby (without the -w option),  
it  
works perfectly. I’ve seen plenty of programs scattered around the net  
that  
use that same line in a shebang line so I know it should work.

Any help would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![croese](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/839c29/32.png) [@croese](https://www.ruby-forum.com/u/croese)\
**Post date:** [February 2, 2008, 8:15pm UTC](https://www.ruby-forum.com/t/env-command/127927/2 "2008-02-02T20:15:57Z")

</div>

On Feb 2, 2008 11:57 AM, Christian R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Any help would be greatly appreciated!
> 
> –  
> Christian R.

> **[Shebang (Unix) | Portability](https://en.wikipedia.org/wiki/Shebang_(Unix)#Portability)**
>
> Shebangs must specify absolute paths (or paths relative to current working directory) to system executables; this can cause problems on systems that have a non-standard file system layout. Even when systems have fairly standard paths, it is quite possible for variants of the same operating system to have different locations for the desired interpreter. Python, for example, might be in /usr/bin/python3, /usr/local/bin/python3, or even something like /home/username/bin/python3 if installed by an or...

Daniel Brumbaugh K.

---

<div class="post-metadata">

**Author:** ![croese](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/839c29/32.png) [@croese](https://www.ruby-forum.com/u/croese)\
**Post date:** [February 2, 2008, 10:25pm UTC](https://www.ruby-forum.com/t/env-command/127927/3 "2008-02-02T22:25:58Z")

</div>

On Feb 2, 2008 1:13 PM, Daniel Brumbaugh K.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > works perfectly. I’ve seen plenty of programs scattered around the net  
> > Daniel Brumbaugh K.

Does this mean I’m hosed on my linux system and I’ll have to use either

/usr/local/bin/ruby -w

or

/usr/bin/env ruby (without the -w switch)

in my programs? Is there any way to delimit these args so that env sees  
them as 2 args instead of one whole string?

---

<div class="post-metadata">

**Author:** ![croese](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/839c29/32.png) [@croese](https://www.ruby-forum.com/u/croese)\
**Post date:** [February 2, 2008, 11:14pm UTC](https://www.ruby-forum.com/t/env-command/127927/4 "2008-02-02T23:14:52Z")

</div>

On Sun, 2008-02-03 at 06:25 +0900, Christian R. wrote:

> > can’t be
> 
> /usr/bin/env ruby (without the -w switch)
> 
> in my programs? Is there any way to delimit these args so that env sees  
> them as 2 args instead of one whole string?

In short, you’re hosed in regards to that particular method.

Unless I’m mistaken, the shebang line is interpreted by the kernel, and  
on Linux it only accepts one parameter to the interpreter the line  
defines - so #!/usr/bin/env ruby -w will always call /usr/bin/env with  
the parameter “ruby -w”, which is not a valid command. There’s no way  
around this.

If, however, all you need this for is the -w switch to turn on warnings,  
just don’t do that with a switch to the ruby binary and use the $VERBOSE  
global variable to turn warnings on and off. The manpage for ruby even  
hints to this:

-w Enables verbose mode without printing version message at  
the beginning. It sets the $VERBOSE variable to true.

That solution should be more portable.

HTH,

Felix

---

<div class="post-metadata">

**Author:** ![croese](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/839c29/32.png) [@croese](https://www.ruby-forum.com/u/croese)\
**Post date:** [February 2, 2008, 11:25pm UTC](https://www.ruby-forum.com/t/env-command/127927/5 "2008-02-02T23:25:27Z")

</div>

On Feb 2, 2008 4:13 PM, fw [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > > and get the correct functionality, but if I use this line in the
> 
> just don’t do that with a switch to the ruby binary and use the $VERBOSE  
> Felix

Nice, I was searching for something like that $VERBOSE variable (much  
akin  
to perl’s ‘use warnings’ capability) and I completely missed that part  
of  
the man page. Thanks
