Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Need Help with First Script

  1. #1
    Join Date
    Apr 2014
    Beans
    5

    Question Need Help with First Script

    Hello,

    I'm trying to write my first script as shown:

    #!/bin/bash

    echo "Hello World!"
    sleep 100

    I saved the file and changed permissions to make it executable. I've also added the script directory to my PATH. When I run the script however I'm given the following error:

    /home/me/bin/script1: 1: /home/me/bin/script1: #!/bin/bash: not found
    Hello World!

    It runs the script however for some reason it sounds like there is an error on the first line.

    Any help would be appreciated.

    Jeremy

  2. #2
    Join Date
    Nov 2009
    Beans
    3,336

    Re: Need Help with First Script

    Works ok .... is your PATH set up for /usr/bin

    K53SV:~$ chmod u+x test1.sh
    K53SV:~$ ./test1.sh
    Hello World!

    K53SV:~$

    K53SV:~$ echo $PATH
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

  3. #3
    Join Date
    Apr 2014
    Beans
    5

    Re: Need Help with First Script

    Yes, my PATH includes my usr/bin directory. Like I said, this script will run however I get that message in front of the Hello World
    "1: /home/me/bin/script1: #!/bin/bash: not found"

    If I include clear in my script before echoing Hellow World I don't see that message but I shouldn't have to do that.

  4. #4
    Join Date
    Nov 2009
    Beans
    3,336

    Re: Need Help with First Script

    What happens if you change your first line to

    #!/usr/bin/bash

  5. #5
    Join Date
    Apr 2014
    Beans
    5

    Re: Need Help with First Script

    Same result but now it says that usr/bin/bash: not found.

    Other scripts I've been experimenting with seem to work fine except for that strange message at the beginning. Not sure if I need to be concerned.

  6. #6
    Join Date
    Apr 2012
    Beans
    7,256

    Re: Need Help with First Script

    Can you show us the outputs of

    Code:
    which bash
    
    cat -net /home/me/bin/script1
    please?

  7. #7
    Join Date
    Apr 2014
    Beans
    5

    Re: Need Help with First Script

    which bash outputs
    /bin/bash

    cat -net /home/me/bin/script1 outputs
    1 M-oM-;M-?#!/usr/bin/bash$
    2 $
    3 $
    4 echo "Hello World!"$
    5 sleep 10$
    6 $

  8. #8
    Join Date
    Nov 2009
    Beans
    3,336

    Re: Need Help with First Script

    Never realised that - is the editing done in windows then ....... as I just used gedit in linux to do my scripts .......

    K53SV:~$ cat -net /home/keith/test1.sh output
    1 #!/bin/bash$
    2 $
    3 echo "Hello World!"$
    4 sleep 100$
    http://unix.ittoolbox.com/groups/tec...script-4986558
    Last edited by 23dornot23d; April 19th, 2014 at 02:48 AM.

  9. #9
    Join Date
    Apr 2012
    Beans
    7,256

    Re: Need Help with First Script

    OK so those funny M-oM-;M-? characters probably come from Windows (they're byte order marks, I think)

    The script is probably "working" because you are running it using sh script1 instead of just script1 - which causes the #! line to be overridden by /bin/sh (usually the dash shell) - please get out of that habit, it causes a lot of confusion.

    Try again from scratch using a native Linux editor (gedit / nano / emacs etc.)

  10. #10
    Join Date
    Apr 2014
    Beans
    5

    Re: Need Help with First Script

    I just rewrote this script in gedit and it worked 100% correctly! The original code was copied from a website and pasted into LibreOffice Writer and saved as text. This must be what caused this problem. I'll have to remember to stick with gedit. Thanks so much for your help!

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

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