Bash 폴더 있는지 확인

1 개요[ | ]

Bash 폴더 있는지 확인
Bash 디렉토리 있는지 확인
  • 절대경로, 상대경로 모두 정상 작동함
mydir='/tmp'
if [ -d $mydir ]; then
    echo "'$mydir' exists."
else
    echo "'$mydir' does NOT exist."
fi
mydir='/tmp'
if [ ! -d $mydir ]; then
  echo "'$mydir' does NOT exist."
fi

2 실행예시1: 절대경로[ | ]

testuser@zetawiki:~$ mydir='/etc/apache2'
testuser@zetawiki:~$ if [ -d $mydir ]; then
>     echo "'$mydir' exists."
> else
>     echo "'$mydir' does NOT exist."
> fi
'/etc/apache2' exists.
testuser@zetawiki:~$ mydir='/etc/asdfasdf'
testuser@zetawiki:~$ if [ -d $mydir ]; then
>     echo "'$mydir' exists."
> else
>     echo "'$mydir' does NOT exist."
> fi
'/etc/asdfasdf' does NOT exist.

3 실행예시2: 상대경로[ | ]

testuser@zetawiki:/etc$ mydir='apache2'
testuser@zetawiki:/etc$ if [ -d $mydir ]; then
>     echo "'$mydir' exists."
> else
>     echo "'$mydir' does NOT exist."
> fi
'apache2' exists.
testuser@zetawiki:/etc$ mydir='asdfasdf'
testuser@zetawiki:/etc$ if [ -d $mydir ]; then
>     echo "'$mydir' exists."
> else
>     echo "'$mydir' does NOT exist."
> fi
'asdfasdf' does NOT exist.

4 같이 보기[ | ]

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