"Bash 쉘스크립트 절대경로 얻기"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-<source lang='cli'> +<source lang='console'>))
1번째 줄: 1번째 줄:
==개요==
==개요==
;Bash 쉘 스크립트 위치 얻기
;Bash 쉘 스크립트 위치 얻기
;Bash 스크립트 폴더 확인
* 쉘스크립트 내부에서 자신이 있는 위치를 절대경로로 얻는 방법
* 쉘스크립트 내부에서 자신이 있는 위치를 절대경로로 얻는 방법
* 어느 위치에서 실행하든 쉘스크립트 파일의 [[절대경로]]를 얻을 수 있음
* 어느 위치에서 실행하든 쉘스크립트 파일의 [[절대경로]]를 얻을 수 있음

2017년 4월 5일 (수) 20:02 판

1 개요

Bash 쉘 스크립트 위치 얻기
Bash 스크립트 폴더 확인
  • 쉘스크립트 내부에서 자신이 있는 위치를 절대경로로 얻는 방법
  • 어느 위치에서 실행하든 쉘스크립트 파일의 절대경로를 얻을 수 있음
script_dir=$(cd "$(dirname "$0")" && pwd)

2 실행 예시

root@zetawiki:~/test# cat hello.sh
script_dir=$(cd "$(dirname "$0")" && pwd)
echo $script_dir
root@zetawiki:~/test# sh hello.sh
/root/test
root@zetawiki:~/test# sh ./hello.sh
/root/test
root@zetawiki:~/test# cd /tmp
root@zetawiki:/tmp# sh /root/test/hello.sh
/root/test
root@zetawiki:/tmp# sh ~/test/hello.sh
/root/test

3 같이 보기

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