# Bang is not work!

**URL:** <https://www.ruby-forum.com/t/bang-is-not-work/160597>\
**Category:** Ruby\
**Created:** [February 18, 2009, 1:59am UTC](https://www.ruby-forum.com/t/bang-is-not-work/160597 "2009-02-18T01:59:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kyung\_won\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/47e85d/32.png) [@Kyung\_won\_C](https://www.ruby-forum.com/u/Kyung_won_C)\
**Post date:** [February 18, 2009, 1:59am UTC](https://www.ruby-forum.com/t/bang-is-not-work/160597/1 "2009-02-18T01:59:12Z")

</div>

OS is CentOs 4.7

$ ruby -v  
ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-linux]

$ cat ruby\_test  
#!/usr/local/bin/ruby

puts ‘hello’

$ ls -l  
-rwxr-xr-x 1 gmc gmc 94 2ì›” 17 19:11 ruby\_test

$ ruby\_test  
-bash: ruby\_test: command not found

################

# Why ???

# Help Me!!

################

---

<div class="post-metadata">

**Author:** ![Kyung\_won\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/47e85d/32.png) [@Kyung\_won\_C](https://www.ruby-forum.com/u/Kyung_won_C)\
**Post date:** [February 18, 2009, 2:08am UTC](https://www.ruby-forum.com/t/bang-is-not-work/160597/2 "2009-02-18T02:08:16Z")

</div>

Kyung won Cheon wrote:

> $ ls -l  
> -rwxr-xr-x 1 gmc gmc 94 2ì›” 17 19:11 ruby\_test
> 
> $ ruby\_test  
> -bash: ruby\_test: command not found
> 
> ################
> 
> # Why ???
> 
> # Help Me!!
> 
> ################

What’s the output of

$ which ruby

What happens with:

$ ./ruby\_test

and

$ ruby ruby-test

---

<div class="post-metadata">

**Author:** ![Kyung\_won\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/47e85d/32.png) [@Kyung\_won\_C](https://www.ruby-forum.com/u/Kyung_won_C)\
**Post date:** [February 18, 2009, 2:45am UTC](https://www.ruby-forum.com/t/bang-is-not-work/160597/3 "2009-02-18T02:45:42Z")

</div>

Kyung won Cheon wrote:

> $ ls -l  
> -rwxr-xr-x 1 gmc gmc 94 2ì›” 17 19:11 ruby\_test
> 
> $ ruby\_test  
> -bash: ruby\_test: command not found

That’s normal. Instead of typing “script\_name”, type “./script\_name”.  
Unless you alias or move ruby\_test to somewhere in your exec path, that  
is (and you probably don’t want that).

---

<div class="post-metadata">

**Author:** ![Kyung\_won\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/47e85d/32.png) [@Kyung\_won\_C](https://www.ruby-forum.com/u/Kyung_won_C)\
**Post date:** [February 18, 2009, 7:18am UTC](https://www.ruby-forum.com/t/bang-is-not-work/160597/4 "2009-02-18T07:18:58Z")

</div>

Bertram S. wrote:

> This is a security feature of your OS/distribution and not about  
> Ruby.
> 
> Suppose you say something like
> 
> $ export PATH=.:"$PATH"
> 
> and the intruder would place a script named “ls” in the current  
> directory…

…and?

---

<div class="post-metadata">

**Author:** ![Kyung\_won\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/47e85d/32.png) [@Kyung\_won\_C](https://www.ruby-forum.com/u/Kyung_won_C)\
**Post date:** [February 18, 2009, 8:44am UTC](https://www.ruby-forum.com/t/bang-is-not-work/160597/5 "2009-02-18T08:44:37Z")

</div>

And, you may end up executing the possibly malicious script instead of  
the original ls when you carelessly type ‘ls’. Regarding the she-bang  
line, I prefer to write ‘#!/usr/bin/env ruby’ rather than to hard-code  
the path of a ruby executable.

2009/2/18 7stud – [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Kyung\_won\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/47e85d/32.png) [@Kyung\_won\_C](https://www.ruby-forum.com/u/Kyung_won_C)\
**Post date:** [February 18, 2009, 3:59am UTC](https://www.ruby-forum.com/t/bang-is-not-work/160597/6 "2009-02-18T03:59:35Z")

</div>

Hi,

Am Mittwoch, 18. Feb 2009, 09:59:29 +0900 schrieb Kyung won Cheon:

> OS is CentOs 4.7
> 
> $ cat ruby\_test  
> #!/usr/local/bin/ruby  
> […]  
> $ ruby\_test  
> -bash: ruby\_test: command not found

This is a security feature of your OS/distribution and not about  
Ruby.

Suppose you say something like

$ export PATH=.:"$PATH"

and the intruder would place a script named “ls” in the current  
directory…

Bertram

---

<div class="post-metadata">

**Author:** ![Kyung\_won\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/47e85d/32.png) [@Kyung\_won\_C](https://www.ruby-forum.com/u/Kyung_won_C)\
**Post date:** [February 18, 2009, 9:34am UTC](https://www.ruby-forum.com/t/bang-is-not-work/160597/7 "2009-02-18T09:34:55Z")

</div>

Choi, Junegunn wrote:

> And, you may end up executing the possibly malicious script instead of  
> the original ls when you carelessly type ‘ls’.

So your not supposed to just type ls at a prompt?

---

<div class="post-metadata">

**Author:** ![Kyung\_won\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/47e85d/32.png) [@Kyung\_won\_C](https://www.ruby-forum.com/u/Kyung_won_C)\
**Post date:** [February 18, 2009, 9:43am UTC](https://www.ruby-forum.com/t/bang-is-not-work/160597/8 "2009-02-18T09:43:24Z")

</div>

> So your not supposed to just type ls at a prompt?

You shouldn’t have ‘.’ (the current) directory in the PATH where the  
shell  
looks for programs to execute, because someone could replace the “real”  
program with one in the current directory.

To the original problem:

a.) either ruby is not in /usr/local/bin  
-\> use `#!/usr/bin/env ruby` instead

b.) ‘.’ is not in the PATH  
-\> don’t change PATH, call your script using `./ruby_test`

c.) you’re script is not executable  
-\> call `chmod +x ruby_test`

or any combination of the above.

-tim

---

<div class="post-metadata">

**Author:** ![Kyung\_won\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/47e85d/32.png) [@Kyung\_won\_C](https://www.ruby-forum.com/u/Kyung_won_C)\
**Post date:** [February 18, 2009, 7:55pm UTC](https://www.ruby-forum.com/t/bang-is-not-work/160597/9 "2009-02-18T19:55:45Z")

</div>

7stud – wrote:

> Choi, Junegunn wrote:
> 
> > And, you may end up executing the possibly malicious script instead  
> > of the original ls when you carelessly type ‘ls’.
> 
> So your not supposed to just type ls at a prompt?

He was saying that without this protection you might not want to. In  
usual cases you do, because this protection exists. It’s one of  
several reasons why you need to set the path, set an alias or type in  
the full path, if it’s not a system command. It’s a good thing.
