Find the answer to your Linux question:
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, ...
  1. #1
    Just Joined! aluminumspleen's Avatar
    Join Date
    Oct 2008
    Location
    Dorm Room, America
    Posts
    59

    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?

  2. #2
    Just Joined! sathiya's Avatar
    Join Date
    Feb 2008
    Location
    Bangalore, India
    Posts
    97
    what does the shell wont have ??

    that file or the commands to change the permission. ???

  3. #3
    Just Joined! aluminumspleen's Avatar
    Join Date
    Oct 2008
    Location
    Dorm Room, America
    Posts
    59
    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

    Code:
    me@comp~$ hello.rb
    I get the "can't find command" bash error.

    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?

  4. #4
    Just Joined! sathiya's Avatar
    Join Date
    Feb 2008
    Location
    Bangalore, India
    Posts
    97
    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.

  5. #5
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    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

  6. #6
    Just Joined! aluminumspleen's Avatar
    Join Date
    Oct 2008
    Location
    Dorm Room, America
    Posts
    59
    Thank you very much Cabhan, I knew there was an easy way to do it from the CL without editing any config files.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...