bang is not work!!

K

Kyung won Cheon

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

Joel VanderWerf

Kyung said:
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!!
################

What's the output of

$ which ruby

What happens with:

$ ./ruby_test

and

$ ruby ruby-test
 
T

Tim Greer

Kyung said:
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

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

Bertram Scharpf

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

7stud --

Bertram said:
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?
 
C

Choi, Junegunn

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

7stud --

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?
 
T

Tim Becker

[Note: parts of this message were removed to make it a legal post.]
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
 
T

Tim Greer

7stud said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top