Find the answer to your Linux question:
Results 1 to 10 of 10
Can anyone help me explain this issue? I tried moving a working script from one SUSE linux system to another and now it crashes on this line: olx8:/usr/odir # more ...
  1. #1
    Just Joined!
    Join Date
    Jul 2004
    Posts
    15

    bad interpreter when running `dirname $0` in sh script

    Can anyone help me explain this issue?

    I tried moving a working script from one SUSE linux system to another and now it crashes on this line:

    olx8:/usr/odir # more test.sh
    #!/bin/sh

    DIRNAME=`dirname $0`

    olx8:/usr/odir # ./test.sh
    : bad interpreter: No such file or directory
    olx8:/usr/odir # which sh
    /bin/sh

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    To help narrow this down, what is the output when you do these two commands?
    Code:
    which bash
    od -t x1 test.sh
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    I'm afraid you have some wrong characters in your script. Does the lines end with CR/LF?
    This can happen if you moved the scripts with ftp with a wrong mode (to Windows and back to Linux).

    Regards

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Yes, that's what I'm expecting. But I'm hoping he can do the od and post the results so I can show him a little bit about the ASCII character set.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  5. #5
    Just Joined!
    Join Date
    Jul 2004
    Posts
    15
    thanks SO much guys for helping me....

    here is what I get on that:

    olx8:/usr/odir # od -t x1 test.sh
    0000000 23 21 2f 62 69 6e 2f 73 68 0d 0a 0d 0a 44 49 52
    0000020 4e 41 4d 45 3d 60 64 69 72 6e 61 6d 65 20 24 30
    0000040 60 0d 0a 0d 0a
    0000045
    olx8:/usr/odir # which bash
    /bin/bash
    olx8:/usr/odir #

  6. #6
    Just Joined!
    Join Date
    Jul 2004
    Posts
    15
    ahhh! thanks you guys! typing "dos2unix test.sh" seems to have fixed it.

    thank you sooo much!

  7. #7
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192

    ASCII school

    Code:
    0000000 23 21 2f 62 69 6e 2f 73 68 0d 0a 0d 0a 44 49 52
    0000020 4e 41 4d 45 3d 60 64 69 72 6e 61 6d 65 20 24 30
    0000040 60 0d 0a 0d 0a
    0000045
    The 0d is the "return" or "carriage return" character. In the old days of teletypes, that character would cause the print element to return to the left edge of the paper. In the even older days when print elements stood still and the paper moved, the carriage which held the paper would move to the right. That's where the "C" in "CR" comes from.

    But that didn't move the paper to the next line. Oh, no, that would be too simple. For that, you needed 0a, which is the "line feed" character. It would feed the paper forward for the distance of one line.

    These days, Microsoft-compatible text files use <CR><LF> to mean end of line, as in your original troublesome file. UNIX and friends use <LF> only, I guess on the theory that it's easier to deal with one end of line character than two. (So this left the extra <CR> in your file as (supposed) real data, to fret over.) And Macintosh uses <CR> only.

    Go figure.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  8. #8
    drl
    drl is online now
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.
    Quote Originally Posted by wje_lf View Post
    ... And Macintosh uses <CR> only.

    Go figure.
    Yes, but that was then -- OS 9 and prior. This is now and for OS X we find:
    Code:
    uname -prs
    Darwin 7.9.0 powerpc
    echo hi | hexdump -C
    00000000  68 69 0a                                          |hi.|
    00000003
    But I would agree that one might need to be careful of a file that came from a Mac ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  9. #9
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Oooo, thanks for the update! I have a question, then.

    Suppose you have an old-style text file. Will OS X read it properly? What about a <CR><LF> type file: Will OS X read that properly? How about OS 9?
    --
    Bill

    Old age and treachery will overcome youth and skill.

  10. #10
    drl
    drl is online now
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi, Bill.

    Those situations are why I keep this around:
    Code:
    % convert
    convert file contents by one of the following methods:
      addcr - adds a carriage return (^M) in front of every line feed (^J)
      delbs - deletes backspaces and bold or underline characters
      delcr - deletes carriage returns from file
      delff - deletes form feeds from file
      b2ul  - converts boldface text in nroff output to underlined
      cr2lf - converts carriage returns to line feeds
      lf2cr - converts line feeds to carriage returns
      indent - indents text 5 spaces
      sp2tab - converts spaces to tabs via "unexpand"
    OS X is unix, for all practical purposes, at the command line ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

Posting Permissions

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