"Bash 폴더 있는지 확인"의 두 판 사이의 차이

20번째 줄: 20번째 줄:
==실행예시==
==실행예시==
<source lang='console'>
<source lang='console'>
testuser@zetawiki:~$ filename='/etc/apache2'
testuser@zetawiki:~$ mydir='/etc/apache2'
testuser@zetawiki:~$ if [ -d $filename ]; then
testuser@zetawiki:~$ if [ -d $mydir ]; then
>    echo "'$filename' exists."
>    echo "'$mydir' exists."
> else
> else
>    echo "'$filename' does not exist."
>    echo "'$mydir' does not exist."
> fi
> fi
'/etc/apache2' exists.
'/etc/apache2' exists.
</source>
</source>
<source lang='console'>
<source lang='console'>
testuser@zetawiki:~$ filename='/etc/asdfasdf'
testuser@zetawiki:~$ mydir='/etc/asdfasdf'
testuser@zetawiki:~$ if [ -d $filename ]; then
testuser@zetawiki:~$ if [ -d $mydir ]; then
>    echo "'$filename' exists."
>    echo "'$mydir' exists."
> else
> else
>    echo "'$filename' does not exist."
>    echo "'$mydir' does not exist."
> fi
> fi
'/etc/asdfasdf' does not exist.
'/etc/asdfasdf' does not exist.

2018년 3월 11일 (일) 15:27 판

1 개요

Bash 폴더 있는지 확인
Bash 디렉토리 있는지 확인
mydir='/tmp'
if [ -d $mydir]; then
    echo "'$mydir' exists."
else
    echo "'$mydir' does not exist."
fi
mydir='/tmp'
if [ ! -f $mydir]; then
  echo "'$mydir' does not exist."
fi

2 실행예시

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 같이 보기

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