[linux] 쉘 스크립트 (Shell Script)
$ (cd /bin ; file * |grep “shell script”) false : Bourne shell script text igawk : Bourne shell script text remadmin : Bourne shell script text true : Bourne shell script text $ (cd /usr/bin ; file * |grep “shell script”) anytopnm : Bourne shell script text apropos : Bourne shell script text audiocompose : C shell script text audiosend : C shell script text autoconf : Bourne shell script text autoheader : Bourne shell script text autoreconf : Bourne shell script text autoupdate : Bourne shell script text bash2bug : Bourne shell script text bashbug : Bourne shell script text batch : Bourne shell script text bdftops : Bourne shell script text bzless : Bourne shell script text ...... whatis : Bourne shell script text wv-incconfig : Bourne shell script text wv-libconfig : Bourne shell script text xbm2ikon : Bourne shell script text xbmcut48 : Bourne shell script text xbmsize48 : Bourne shell script text zcmp : Bourne shell script text zdiff : Bourne shell script text zforce : Bourne shell script text zgrep : Bourne shell script text zipgrep : Bourne shell script text zless : Bourne shell script text zmore : Bourne shell script text znew : Bourne shell script text |
$ cat findscript #!/bin/sh# # findscript: /bin, /usr/bin에 있는 쉘 스크립트를 찾는다. # (cd /bin; file * | grep “shell script”) (cd /usr/bin; file * | grep “shell script”) $ chmod +x findscript.sh $ ./findscript.sh |
$ who | grep root $ echo $? 1 $ who | grep hermes44 hermes44 : 0 Sep 16 11:34 hermes44 pts/0 Sep 16 11:36 hermes44 pts/1 Sep 16 14:07 $ echo $? 0 $ false; echo $? 1 $ true; echo $? 0 |
$ cat return_exit #!/bin/sh # #return_exit: <인자>의 값을 종료 상태로 #반환한다. # if [ $# -eq 0 ] then exit else exit $1 fi $ ./return_exit; echo $? 0 $ ./return_exit 8; echo $? 8 if 구문은 조건식에 따라서 분기를 한다. 형식은 다음과 같다. if 조건식 then 명령들 [ elif 조건식 then 명령들 ] [ else 명령들 ] fi |
$ cat trap_exit #!/bin/sh # #trap_exit: trap 테스트 # trap ‘echo basename $0: signal catch’ 1 2 15 trap ‘echo script exit; exit’ 3 while : do echo loop done $ ./trap_exit |
#!/bin/sh # # prarg: 세 개의 인자를 출력하다. # prog= basename $0 if [$# -eq 3 ] then echo “Script $prog path: $0” echo “Arg1: $1” echo “Arg2: $2” shift echo “Arg3: $2” else echo “Usage: $ $prog arg1 arg2 arg3” exit fi $ ./prog es 34 Usage: $ prarg arg1 arg2 arg3 $ ./prog 28 ksl 9 Script prarg path: ./prarg Arg1: 28 Arg2: ksl Arg3: 9 |
$ cat arg-while #!/bin/sh # # arg-while: 모든 인자를 출력한다. # echo Argument number: $# while [ $# -gt 0 ] do echo $1 shift done $ ./arg-whilel 1 2 3 4 Argument number: 4 1 2 3 4 |
$ cat arg-until #!/bin/sh # # arg-until: 모든 인자를 출력한다. # echo Argument number: $# until [ $# -eq 0 ] do echo $1 shift done $ ./arg-until 1 2 3 4 Argument number: 4 1 2 3 4 |
$ cat arg-for # !/bin/sh # # arg-for: @ 인자앞의 인자를 출력한다. # echo Argument number: $# for arg do if [ $arg = @ ] then break fi echo $arg done $ ./arg-for 1 2 @ 3 2 4 6 Argument number: 7 1 2 |
$ cat check-flag #!/bin/sh # # check_flag: 인자를 검사하여 flag를 켠다. # aflag=0 bflag=0 for arg do case $arg in -a) aflag=1 ;; -b) bflag=1 ;; *) echo “Usage: `basename $0` [-a] [-b]” 1>&2 exit 1 ;; esac done echo aflag=$aflag bflag=$bflag $ ./check-flag aflag=0 bflag=0 $ ./check-flag -a aflag=1 bflag=0 $ ./check-flag -a -b aflag=1 bflag=1 |
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
405 | Develop |
[c] 텍스트 파일(로그)을 정해진 라인 단위로 쪼개주는 코드
![]() |
hooni | 2013.04.23 | 7051 |
404 | Develop | [C++] 18일차 과제물, String 클래스 디자인 【 C++ 문제 】 | hooni | 2013.04.23 | 7047 |
403 | Develop | [c++] 소켓 프로그래밍 관련 링크.. (퍼올려고 올린거) | hooni | 2013.04.23 | 7036 |
402 | Develop |
[c] 단어 입력/수정 프로그램 소스
![]() |
hooni | 2003.04.23 | 7029 |
401 | Develop |
[c] openssl 샘플코드.. 어려움 ㅠㅠ
![]() |
hooni | 2013.04.23 | 7028 |
400 | Develop |
[c] 내가 만든 암호화 프로그램.. 좋아^^
![]() |
hooni | 2013.04.23 | 7027 |
399 | Develop |
[c] 정사각배열의 서브 배열의 최대 값 구하기
![]() |
hooni | 2003.04.23 | 7025 |
398 | Develop | [js] 큐 형식으로 배열사용.. ㅋㅋ | hooni | 2013.04.23 | 7022 |
397 | Develop |
[c] 패스워드 암호화/사용자 정보 보기
![]() |
hooni | 2003.04.23 | 7016 |
396 | Develop |
[c] C에서 MySQL DB 사용하기~
![]() |
hooni | 2003.04.23 | 7011 |
395 | Develop |
[c][java] 소켓 프로그래밍(채팅 서버 C, 클라이언트 Java)
![]() |
hooni | 2003.04.23 | 7011 |
394 | Develop | [js] 이미지 미리 로딩하기 | hooni | 2003.04.23 | 7008 |