Results 1 to 6 of 6
Hey, I'm learning Ruby, and I'm trying to get the whole "shebang" (#!) thing to work, but even when I put the correct path at the top of my file, ...
- 01-20-2009 #1
Shebang?
Hey, I'm learning Ruby, and I'm trying to get the whole "shebang" (#!) thing to work, but even when I put the correct path at the top of my file, I get a "command not found" error. I tried changing the permissions to allow the file to be executed, but the shell won't have it. Any ideas?
- 01-20-2009 #2
what does the shell wont have ??
that file or the commands to change the permission. ???
- 01-20-2009 #3
hey, thanks for the quick reply.
i'm sorry, that's just slang. by "the shell won't have it", I meant when I just type in
I get the "can't find command" bash error.Code:me@comp~$ hello.rb
This does make sense to me, but if I have the "shebang", shouldn't it recognize the file as a script, and treat it as such? Or do I need to do something to tell the machine to read the first line?
- 01-20-2009 #4
1. You need to have the CURRENT DIR in the PATH var.
2. You need to have execute permission for that file.
Thats all, when you have these both, this file will be executed by referring the shebang line.
- 01-22-2009 #5
So let's explain a bit more.
When you type anything into the shell, it assumes that the first "word" is the name of the command, and any following words are arguments. To find the command, it looks at all of the directories in the $PATH variable. In your case, it's searching all of these directories for a file called "hello.rb". Obviously, it will not find it.
To override this behaviour (for instance, to run a script), you can make the first word into a path to a script. For instance, you might run /home/user/my_scripts/foo_script. In this case, the shell won't check $PATH, it will just use this direct script.
For this, you can use either absolute or relative paths. In order to run a script in the current directory, therefore, you just run "./hello.rb". This means "Look in the current directory for a program called hello.rb". Once it finds this file, it will check the shebang line, and execute it correctly.
It is generally a bad idea to add "." to $PATH, because that will cause anything in the current directory to be easily executable. It's obviously very easy to exploit this to maliciously execute programs.DISTRO=Arch
Registered Linux User #388732
- 01-23-2009 #6
Thank you very much Cabhan, I knew there was an easy way to do it from the CL without editing any config files.


Reply With Quote