IT

bash에서 현재 작업 디렉토리를 임시로 변경하여 명령을 실행하십시오.

lottoking 2020. 6. 8. 08:04
반응형

bash에서 현재 작업 디렉토리를 임시로 변경하여 명령을 실행하십시오. [중복]


cdbash에서 작업 디렉토리를 변경 하는 명령을 사용할 수 있다는 것을 알고 있습니다 .

그러나이 명령을 수행하면 :

cd SOME_PATH && run_some_command

그런 다음 작업 디렉토리가 영구적으로 변경됩니다. 이와 같이 일시적으로 작업 디렉토리를 변경하는 방법이 있습니까?

PWD=SOME_PATH run_some_command

cd명령 행을 괄호로 묶어 서브 쉘에서 및 실행 파일을 실행할 수 있습니다 .

(cd SOME_PATH && exec_some_command)

데모:

$ pwd
/home/abhijit
$ (cd /tmp && pwd)  # directory changed in the subshell
/tmp 
$ pwd               # parent shell's pwd is still the same
/home/abhijit

bash는 내장되어 있습니다

pushd SOME_PATH
run_stuff
...
...
popd 

이와 같은 것이 작동해야합니다.

sh -c 'cd /tmp && exec pwd'

참고 URL : https://stackoverflow.com/questions/10382141/temporarily-change-current-working-directory-in-bash-to-run-a-command

반응형