noob: How to make my script executable on unix?

Discussion in 'Ruby' started by rpardee@gmail.com, Dec 20, 2006.

  1. Guest

    Hey All,

    At a bash prompt, if I say 'which ruby', I get back
    '/opt/csw/bin/ruby'.

    So I write a 2-line test script (test.rb):
    #!/opt/csw/bin/ruby
    puts("It works!")

    And I do a 'chmod +x test.rb'.

    But when I thereafter say 'test.rb', bash comes back with:
    bash: ./test.rb: bad interpreter: No such file or directory

    What am I doing wrong?

    Thanks!

    -Roy
     
    , Dec 20, 2006
    #1
    1. Advertising

  2. Peter Szinek Guest

    wrote:
    > Hey All,
    >
    > At a bash prompt, if I say 'which ruby', I get back
    > '/opt/csw/bin/ruby'.
    >
    > So I write a 2-line test script (test.rb):
    > #!/opt/csw/bin/ruby
    > puts("It works!")
    >
    > And I do a 'chmod +x test.rb'.
    >
    > But when I thereafter say 'test.rb', bash comes back with:
    > bash: ./test.rb: bad interpreter: No such file or directory
    >
    > What am I doing wrong?

    Are you sure it can not be a CR/LF problem (or some other trailing
    invisible stuff)? This is probably the most frequent cause of this
    problem (e.g. when moving the script from win32 to linux - but since I
    guess you are on linux only - well, I don't know)

    Otherwise, what you are doing seems fine to me...

    Cheers,
    Peter

    __
    http://www.rubyrailways.com
     
    Peter Szinek, Dec 20, 2006
    #2
    1. Advertising

  3. Guest

    Hah--right you are--thanks! I'm actually on solaris, but writing my
    script on windows (ultraedit) and saving to a samba share. Ultraedit
    has a 'DOS -> Unix' conversion, but it doesn't seem to affect the
    executability of my script. :-( But if I write the same lines to a new
    file in pico, then it works.

    Thanks!

    -Roy

    Peter Szinek wrote:
    > wrote:
    > > Hey All,
    > >
    > > At a bash prompt, if I say 'which ruby', I get back
    > > '/opt/csw/bin/ruby'.
    > >
    > > So I write a 2-line test script (test.rb):
    > > #!/opt/csw/bin/ruby
    > > puts("It works!")
    > >
    > > And I do a 'chmod +x test.rb'.
    > >
    > > But when I thereafter say 'test.rb', bash comes back with:
    > > bash: ./test.rb: bad interpreter: No such file or directory
    > >
    > > What am I doing wrong?

    > Are you sure it can not be a CR/LF problem (or some other trailing
    > invisible stuff)? This is probably the most frequent cause of this
    > problem (e.g. when moving the script from win32 to linux - but since I
    > guess you are on linux only - well, I don't know)
    >
    > Otherwise, what you are doing seems fine to me...
    >
    > Cheers,
    > Peter
    >
    > __
    > http://www.rubyrailways.com
     
    , Dec 20, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    15
    Views:
    498
    Dave Thompson
    Aug 21, 2006
  2. pratap
    Replies:
    20
    Views:
    774
    Flash Gordon
    Mar 7, 2007
  3. Jason Cavett
    Replies:
    8
    Views:
    637
    Sanjay
    May 16, 2007
  4. Replies:
    0
    Views:
    452
  5. Replies:
    2
    Views:
    182
    RedGrittyBrick
    Apr 21, 2007
Loading...

Share This Page