Double-clicking a Bash script and having it execute in it's directory

Discussion in 'Apple' started by Bassam, Sep 26, 2006.

  1. Bassam

    Bassam Guest

    Hi. I'm having some trouble with a Bash script I've been working on in
    OS X.

    The first command in the script is to copy all of the contents of the
    directory it's located in (including itself) to another folder.

    The Bash command I'm using is:
    cp -R . "/Some/Other/Folder/"

    This works fine when I run the program from the Terminal. E.g.:

    But, I need this script to be double clickable in the Finder. I've
    associated it with Terminal, but when I double-click on it, instead of
    copying the files from the script's local folder, it starts recursively
    copying files from the home folder!

    I think this is because when I double-click on the script, it starts a
    new Terminal window at the home folder, and the dot portion of "cp ."
    now refers to the home folder, instead of the directory containing the

    Can anyone help me figure out how to be able to double click on the
    script to run it, yet have the script start in it's original folder?

    Thanks for any help.
    Bassam, Sep 26, 2006
    1. Advertisements

  2. Bassam

    Hans Aberg Guest

    Use full paths "/...", or relative home "~/...".
    Hans Aberg, Sep 26, 2006
    1. Advertisements

  3. Bassam

    Bob Harris Guest


    cp -R "${0%/*}/" "/Some/Other/Folder/"


    Bob Harris
    Bob Harris, Sep 26, 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.