Find the answer to your Linux question:
Results 1 to 7 of 7
Write the fist hello.sh bash script as follows: -------------------------------- # hello.sh # This is my first shell script printf "Hello! Bash is wonderful." exit 0 -------------------------------- # bash hello.sh : ...
  1. #1
    Just Joined!
    Join Date
    Jul 2006
    Posts
    60

    : command not found in the first bash script

    Write the fist hello.sh bash script as follows:

    --------------------------------
    # hello.sh
    # This is my first shell script

    printf "Hello! Bash is wonderful."
    exit 0
    --------------------------------
    # bash hello.sh
    : command not found

    When I ran this script, I got a command not found error in the shell, what am I doing wrong here? Note if I delete the empty line, I got a different error.

    # bash hello.sh
    : numeric argument required

    Also if I delete the "exit 0", I got nothing on the output.
    # bash hello.sh
    #


    Need help on this, Thanks
    Jiafan

  2. #2
    Blackfooted Penguin daark.child's Avatar
    Join Date
    Apr 2006
    Location
    West Yorks
    Posts
    4,344
    Try using echo instead of printf e.g.
    Code:
    #!/bin/bash
    #This is my first shell script
    
    echo "Hello! Bash is wonderful."
    exit 0

  3. #3
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    I'm thinking there might be invisible garbage in that script.

    What editor are you using to write it? In other words, what program are you running at the moment you're actually typing the content of the script?
    --
    Bill

    Old age and treachery will overcome youth and skill.

  4. #4
    Just Joined!
    Join Date
    Jul 2006
    Posts
    60
    Actually you are right. I used editplus in Windows and copied it to a linux box. When I use the vi in Linux, this script works fine. Problem solved.

    Thanks for giving me the hint.
    Jiafan

  5. #5
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    For a bit more information: Linux (and indeed, all Unices, including Mac OS X) uses the LF character exclusively to represent newlines. Windows uses the sequence CRLF to represent newlines. As a result, when a file is written in Windows, it has CRs scattered everywhere throughout it. Many Linux editors will display the file properly anyway, which is good for many people, but for scripters / programmers, it is obviously a problem.

    You can use the utility dos2unix (or for the other direction, unix2dos) to normalize all newlines in a text file.
    DISTRO=Arch
    Registered Linux User #388732

  6. #6
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    That won't necessarily fix everything, and I suspect it wasn't enough here. Some "editors" in Windows don't store the data as pure text with CRLF line endings; they store additional formatting data. In that case, dos2unix (or, on my Slackware system, fromdos) won't be enough.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  7. #7
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    I just went to the editplus web page, and my guess is that they do not insert additional formatting data into the text; the only unwelcome addition would be the CR before each LF, as Cabhan suggests.

    Yet, the error messages that JiafanZhou was getting suggest to me that something else was going on. I suspect that there was some other editor involved somehow. It's a mystery, but I'm happy that JiafanZhou's problem is solved and he can move on.
    --
    Bill

    Old age and treachery will overcome youth and skill.

Posting Permissions

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