0
PROMPT> pwd
/Users/jon/dev/test

PROMPT> ls -al
total 8
drwxr-xr-x   3 jon   102B Aug 27 21:34 ./
drwxr-xr-x  14 jon   476B Aug 27 21:33 ../
-rwxr-xr-x   1 jon   147B Aug 27 21:34 init*

PROMPT> cat init
#!/bin/sh
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export SCRIPT_HOME=${DIR%/bin}
echo "SCRIPT_HOME has been set to: $SCRIPT_HOME"

PROMPT> ./init
SCRIPT_HOME has been set to: /Users/jon/dev/test

PROMPT> echo $SCRIPT_HOME

PROMPT> why did that command not work?
-bash: why: command not found

PROMPT> 
2
  • 1
    export makes a shell variable available to any subprocesses of the shell in which it was defined, but not to the parent process of the shell in which was defined. Commented Aug 28, 2013 at 1:56
  • 1
    source the script instead. Commented Aug 28, 2013 at 2:21

1 Answer 1

1

Instead you should try the following :

PROMPT>. ./init

Notice the extra dot . and the space between ./init. That is important. It is similar to source init.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.