출처 : http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script

Shell scripts are run inside a subshell, and each subshell has its own concept of what the current directory is. The cd succeeds, but as soon as the subshell exits, the previous current directory is restored.

One way to get around this is to use an alias instead:

alias proj="cd /home/tree/projects/java"


쉘 스크립트는 서브 쉘 내에서 동작하고, 각각의 서브 쉘은 현재 디렉토리의 컨셉을 가지고 있음. cd 명령은 성공하지만 서브쉘에서 나가기 때문에, 현재 디렉토리로 복원됨.

그래서 .profile 등에 alias 를 사용하여 처리하는 것이 좋음.

+ Recent posts