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

(새 문서: ==개요== ;Bash 폴더 있는지 확인 ;Bash 디렉토리 있는지 확인 <source lang='bash'> filename='/etc' if [ -f $filename ]; then echo "'$filename' exists." else ec...)
 
 
(사용자 2명의 중간 판 9개는 보이지 않습니다)
2번째 줄: 2번째 줄:
;Bash 폴더 있는지 확인
;Bash 폴더 있는지 확인
;Bash 디렉토리 있는지 확인
;Bash 디렉토리 있는지 확인
* 절대경로, 상대경로 모두 정상 작동함


<source lang='bash'>
<syntaxhighlight lang='bash'>
filename='/etc'
mydir='/tmp'
if [ -f $filename ]; then
if [ -d $mydir ]; then
     echo "'$filename' exists."
     echo "'$mydir' exists."
else
else
     echo "'$filename' does not exist."
     echo "'$mydir' does NOT exist."
fi
fi
</source>
</syntaxhighlight>
<source lang='bash'>
<syntaxhighlight lang='bash'>
filename='/etc'
mydir='/tmp'
if [ ! -f $filename ]; then
if [ ! -d $mydir ]; then
   echo "'$filename' does not exist."
   echo "'$mydir' does NOT exist."
fi
fi
</source>
</syntaxhighlight>
 
==실행예시1: 절대경로==
<syntaxhighlight lang='console'>
testuser@zetawiki:~$ mydir='/etc/apache2'
testuser@zetawiki:~$ if [ -d $mydir ]; then
>    echo "'$mydir' exists."
> else
>    echo "'$mydir' does NOT exist."
> fi
'/etc/apache2' exists.
</syntaxhighlight>
<syntaxhighlight lang='console'>
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.
</syntaxhighlight>
 
==실행예시2: 상대경로==
<syntaxhighlight lang='console'>
testuser@zetawiki:/etc$ mydir='apache2'
testuser@zetawiki:/etc$ if [ -d $mydir ]; then
>    echo "'$mydir' exists."
> else
>    echo "'$mydir' does NOT exist."
> fi
'apache2' exists.
</syntaxhighlight>
<syntaxhighlight lang='console'>
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.
</syntaxhighlight>


==같이 보기==
==같이 보기==

2023년 10월 16일 (월) 22:35 기준 최신판

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 }}