Bang is not work!


#1

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!!

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


#2

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


#3

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


#4

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?


#5

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:


#6

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


#7

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?


#8

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


#9

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.