사용자 도구

사이트 도구


linux:shell

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판이전 판
linux:shell [2024/11/12 16:56] taekgulinux:shell [2025/04/15 10:05] (현재) – 바깥 편집 127.0.0.1
줄 1: 줄 1:
 +<code bash>
 +#!/bin/bash
  
 +# 디렉토리 존재 유무 확인
 +if [ ! -d 디렉토리명 ] ; then
 +  mkdir 디렉토리명
 +fi
 +
 +# 파일 존재 유무 확인
 +if [ ! -e 디렉토리명 ] ; then
 +  touch 파일명
 +fi
 +
 +if test -f "manage.py"; then
 +  echo ls -l manage.py
 +fi
 +
 +file_name="my_file.txt"
 +# 파일이 있을 경우 메세지 출력
 +if test -e $file_name
 +  then echo "$file_name 파일을 찾았습니다."
 +fi
 + 
 +# 파일이 없을 경우 메세지 출력(! 사용)
 +if ! test -e $file_name
 +  then echo "$file_name 파일이 없습니다."
 +fi
 + 
 +# 디렉토리의 존재 여부는 -d 옵션을 사용하면 된다.
 + 
 +dir_name="/var/log/"
 +# 디렉토리가 있을 경우 메세지 출력
 +if test -d $dir_name
 +  then echo "$dir_name 디렉토리를 찾았습니다."
 +fi
 + 
 +# test 명령은 대괄호([ ])로 대체해서 쓸 수도 있다. 바로 위의 if 조건문 예시를 아래과 같이 써도 된다.
 + 
 +if [ -d $dir_name ]
 +  then echo "$dir_name 디렉토리를 찾았습니다."
 +fi
 +</code>