why this simple bash script doesn't run on my G5 OS X Tiger?

Discussion in 'Apple' started by Key-Rok Choi, May 30, 2006.

  1. Key-Rok Choi

    Key-Rok Choi Guest

    Hi, All,

    This is my first try to use shell scripts on Mac. And I can't figure out
    why this simple script doesn't run.

    $> vi testscript.sh
    echo "Hello Test"

    $> ls -l
    -rwxr-xr-x 1 kr kr 28 May 30 00:41 testscript.sh

    $> testscript.sh
    -bash: run: command not found

    So, what am I missing here. I checked "Excute this
    command..." as "/bin/bash", but it should run anyway according to the
    guide on the Mac web site.

    The command line,
    $>echo "Hello"
    works fine though.

    Thanks in advance,

    Key-Rok Choi, May 30, 2006
    1. Advertisements

  2. That's a bit obscure. What he needs to know is that an executable has to
    be in the "executable path" that you've set in your $PATH environment
    variable. Otherwise you have to give the full path to the thing.

    ../ is shorthand for "this directory" or "the working directory" or

    If you're going to play with a lot of scripts, it might be worthwhile to
    create a bin directory in your home directory, and move the scripts
    there, and then add $HOME/bin to your path (in your .bashrc file). Then
    you can just type the command anywhere you happen to be parked.
    Prester Jacques, May 30, 2006
    1. Advertisements

  3. Key-Rok Choi

    lidstah Guest

    Hello Key-Rok,
    well first, check there is a space between #! and /bin/bash,
    i.e : #! /bin/bash, as it seems you forget it (at least in your post).

    the second thing is that, after having created the file, you'll have to
    change its permissions in order to make it "executable" (it is just
    considered as an read/write document when saving it in vi, and then
    won't execute, except if you use the command bash testscript.sh (and i'm
    not sure it'll work)), using the command (in terminal) : chmod +x
    testscript.sh (in the directory you created the file testscript.sh)

    the third thing is that you probably created the testscript.sh file in
    your user's directory ( /Users/your_user_name/testscript.sh, also noted
    with a tilde), so you have to use the ./testscript.sh command in your
    user's directory in order to run it, until you move it in the /usr/bin/
    directory (you'll need administrator privileges to do this), with a
    command like : sudo mv testscript.sh /usr/bin/, and then it'll launch
    just invoking its command on the prompt.

    Hope it'll help, and that I haven't done to much mistakes, because my
    english is somewhat approximative,
    lidstah, Jun 1, 2006
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.