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 구차니
어쩌면 당연한걸지도 모르겠지만..
리눅스와 윈도우의 개행은 CR+LF / LF로 차이가 크다.

vi에서 보면
CR+LF는 ^M이 붙는데,
이로 인해서 쉘에서 인식을 제대로 못하고
실행을 못하는 문제가 생긴다.


bash에서는 문제가 없었던거 같은데.. 흐음..
아무튼 busybox에서 사용하는 ash의 경우에는 CR+LF의 경우에는
제대로 안되니 반드시 확인을 해야한다.


(이걸로 일주일 공쳤네 ㄱ-)
Posted by 구차니
Linux2009. 8. 4. 15:45
bash 쉘 스크립트에서 변수를 선언하는 방법은 다음과 같다.
VARIABLE=VALUE

그리고 변수를 읽는 방법은 다음과 같다.
VAR2=$VARIABLE

아무튼, 다른 변수에 변수들을 조합해서 내용을 넣는데
공백이 들어가는 문자열의 경우에는 한번에 변수로 들어가지 않는다.
$ test=123 456 789
-bash: 456: command not found

그런 이유로, 문자열은 " "로 넣어주어야 한다.
$ test="123 456 789"

' '는 안에 변수가 있다고 하더라도 치환하지 않고 그냥 출력한다.
$ test="123 456 789"
$ echo '$test'
$test

{}는 함수이다. 즉, 어떠한 내용을 변형 후 값으로 사용하려면 ${} 라고 하면된다.
()는 변수를 감싸준다. 그냥 $(VAR) 이런식으로 사용한다.

선언되지 않은 변수를 사용할 경우에는 null 문자이므로 출력되지 않으나(bash에서)
busybox(ver 1.10.1) 에서는 오작동을 하는 문제가 보였다.

예를 들어
VAR="test string $undefined hello world"를 출력하려고 하면
hello world만 나온다.


참고 링크
[링크 : http://kaludin.egloos.com/2334564]
[링크 : http://wiki.kldp.org/HOWTO//html/Adv-Bash-Scr-HOWTO/index.html]

'Linux' 카테고리의 다른 글

busybox route 명령어  (0) 2009.08.06
grep -r 옵션은 주의!  (0) 2009.08.06
bash - eval  (0) 2009.08.03
/proc/cmdline 내용 읽어오기  (0) 2009.08.03
setenv() - change or add an environment variable  (4) 2009.08.03
Posted by 구차니
Linux2009. 8. 1. 13:04
var=$(cat filename)



참~~~ 쉽죠~
(찾는데 한참 걸림 ㅠ.ㅠ)


[링크 : http://wonylog.tistory.com/192]
[링크 : http://ttongfly.net/zbxe/?document_srl=45340&mid=scriptprogramming]
Posted by 구차니
Linux2008. 12. 18. 11:24
CALL source or . (dot operator) "include" another script

[출처 : http://tldp.org/LDP/abs/html/dosbatch.html]



In the last syntax ./ means current directory, But only . (dot) means execute given command file in current shell without starting the new copy of shell, The syntax for . (dot) command is as follows
Syntax:
. command-name
[출처 : http://www.freeos.com/guides/lsst/ch02sec01.html]




간단하게 환경변수를 쓰기 위해 만든 스크립트를 단순하게
실행하면, 별도의 쉘이 생성이 되어 실행되므로 현재 쉘에 적용이 되지 않는다.

그런 이유로 일반적으로 환경 변수로 사용하기 위한 스크립트를 실행 할때는 반드시
source [script.file] 로 실행을 한다.

source [script.file]와 동일하게
. [script.file] 을 실행해도 된다.
Posted by 구차니