2010-12-07 2 views
2

I 쉘 스크립트에 다음 줄이 :소스는 쉘 스크립트 내에서 작동하지

source bash_profile 

그것은처럼 내 별명을 다시로드 아니에요 (그것은 오류가 없지만, 내가 중 하나를 볼 수 있습니다 아무것도하지 않습니다 예)

그러나 쉘 스크립트가있는 폴더에서 쉘에서 명령을 실행하면 예상대로 작동합니다.

스크립트 내에서 디렉토리를 변경하지 않습니다.

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 

내가가와 bash_profile에서 변화를 관리하고 자식의 repo에 저장하는 스크립트를 사용 : 사실, 여기에 스크립트입니다.

왜 쉘 스크립트 내에서 소스 명령이 작동하지 않습니까?

+2

당신도 스크립트를 소싱하고 있습니까?'source thescriptname'? 그렇지 않으면 스크립트는 새로운 쉘에서 수행되고'source bash_profile' 명령은 새로운 쉘 (스크립트의 끝에서 종료 됨)에 영향을줍니다. –

+1

답으로 답하면 받아 들일 것입니다. "source theScript.sh"를 입력하는 대신 "theScript.sh"라는 스크립트 이름을 입력하여 스크립트를 실행했습니다. 감사! – cmcculloh

+1

당신은 @Bert를 말해야 만합니다. –

답변

10

스크립트를 소싱하고 있습니까? source thescriptname? 그렇지 않으면 스크립트가 새 셸에서 실행되고 source bash_profile 명령은 새 셸 (스크립트의 끝에서 종료 됨)에 영향을줍니다.