2

I have the following line in a shell script:

source bash_profile

It does not error, but it does not do anything that I can see either (It's not reloading my aliases like I expect)

However, from the same folder that the shell script is in, if I just run the command from the shell, it works like I expect.

I never change directories from within the script either. In fact, here is the script:

direction="to"
destination="local"
if [ -n $1 ]
    then
    direction=$1
fi
if [ -n $2 ]
    then
    destination=$2
fi

command=$direction$destination

if [ $command = "fromlocal" -o $command = "togit" ]
    then
    cp /c/Program\ Files/Git/etc/bash_profile /d/automata/flgitscripts/bash_profile
else
    cp /d/automata/flgitscripts/bash_profile /c/Program\ Files/Git/etc/bash_profile
fi

source /c/Program\ Files/Git/etc/bash_profile

I use the script to manage changes to and from the bash_profile and store them in a git repo.

Why isn't the source command working from within the shell script?

4
  • 2
    Are you sourcing the script too: source thescriptname? Otherwise the script is running in a new shell and the source bash_profile command is affect that new shell (which exits at the end of the script). Commented Dec 7, 2010 at 19:12
  • 1
    Put this as the answer and I will accept. I was running the script just by typing the script name "theScript.sh" instead of typing "source theScript.sh". Thanks! Commented Dec 7, 2010 at 19:24
  • 1
    You have to say @Bert or he might never see it. Commented Dec 7, 2010 at 21:34
  • 1
    Thanks @Dennis Williamson for the @ poke :-) @cmcculloh - comment posted as answer. Thanks. Commented Dec 7, 2010 at 21:38

1 Answer 1

10

Are you sourcing the script too: source thescriptname? Otherwise the script is running in a new shell and the source bash_profile command affects that new shell (which exits at the end of the script).

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.