Bash 쉘스크립트 상대경로 얻기

Jmnote (토론 | 기여)님의 2015년 3월 11일 (수) 17:12 판 (→‎방법)
What directory a bash script file is stored in?
Bash 파일 디렉토리 확인
Bash 파일 있는 폴더 확인

1 방법

DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd
실행예시
[root@zetawiki ~]# cat /tmp/test.sh 
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
echo $DIR
[root@zetawiki ~]# sh /tmp/test.sh
/tmp

2 참고 자료

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}