'if test'에 해당되는 글 1건

  1. 2009.11.18 쉘 스크립트에서 파일 존재유무 확인하기
Linux2009. 11. 18. 16:03
if [ -f filename] 으로 파일의 유무를 확인할 수 있다.
물론 그 파일이 존재한다 하더라도 깨어진 심볼릭 링크라면 없는 파일로 나온다.
.. 당연한건가?

$ cat broken_link.sh
#/bin/sh
if [ -f test ]
then
        echo test exist
else
        echo test not exist
fi

$ ls -al
total 60
-r-xr-xr-x 1 morpheuz dev   71 Nov 18 15:37 broken_link.sh
lrwxrwxrwx 1 morpheuz dev    2 Nov 18 15:36 test -> tt

$ ./broken_link.sh
test not exist

$ touch tt
$ ls -al
total 60
-r-xr-xr-x 1 morpheuz dev   71 Nov 18 15:37 broken_link.sh
lrwxrwxrwx 1 morpheuz dev    2 Nov 18 15:36 test -> tt
-rw-rw-r-- 1 morpheuz dev    0 Nov 18 15:40 tt

$ ./broken_link.sh
test exist

[링크 : http://freeos.com/guides/lsst/ch03sec02.html]

'Linux' 카테고리의 다른 글

ps - Process Status  (2) 2009.11.20
pidfile family - pidfile_open, pidfile_remove, pidfile_write, pidfile_close  (0) 2009.11.20
리눅스 셸스크립트 튜토리얼  (2) 2009.11.17
Fedora Core 12  (0) 2009.11.17
UVC - USB Video Class  (0) 2009.11.17
Posted by 구차니