티스토리 뷰

IoT 과정

Branches and Logic Testing

gaelim 2017. 7. 6. 15:17
반응형

.exrc => vi setting

tabstop => tab indentation

shiftwidth => shift movement  ( shift move cmd "shift + < or >")

number => line number

/usr/bin/ex hard link with /usr/bin/vi, vi command mode 에서 : 뒤 명령어 wq, q! 등의 command는 ex 의 command 이다.


branch and loop ... UNIX의 keyword

from pre-ALGOL, loop syntax's history starts. ... the begin of Structured Programming Language. 
branch single (if), multiple (case)
loop for, while, until


branch and loop ... C는 integer로, java는 boolean, Shell은 return 값으로 결정


test, [ ... ]

...기존에 알던 컴퓨터 언어 때문에 더욱이 헷갈리는 keyword 중 하나다...

test -a file : if file exists, then true
test -d file : if file exists and is a directory, then true
test -f file : if file exists and is an ordinary file, then true
string = patter if string matches patter then true

[ 1 -lt 3 ] : true
[ "$var" = 123 ] .. 변수에 double quoting을 하는 것이 안전하다. 변수값이 null이 있을 경우 안전하다.

$ [ $x -ge 2 -a $x -lt 5 ]
$ echo $?
0

$ [[ $x -ge 2 && $x -lt 5 ]]
$ echo $?
0

$ (( $x >= 2 && $x < 5 ))
$ echo $?
0


if ... [[]], (())
then ... 
fi

if ...
then ...
else ...
fi 

if ...
then ...
elif ...
then ...
fi

if 문을 처음 쓰면서 만나는 것들

:set all { autoindent, autoindent에서 한칸 나오는법 ctrl + d, 또는 들여쓰기 shift + <, >, shift 이동은 set all에서 shiftwidth에서 확인가능. indentation 또는 yank. delete를 효율적이게 이용하는 방법 marking command, 마킹명령어 m"임의의 캐릭터, 26가지의 조합" // 팁은 mm <- 손 접근이 빠르기 때문,  현 위치에서 마킹 m 까지 indentation은 => shift + > + ' + m , 그냥 마킹까지 이동은 => ' + m  

case $var in        //$var 하는 것을 깜빡하면안된다, var을 넘기면 var 자체로 패턴매칭을하므로 주의
   choice_1) ... ;;
   choice_2) ... ;;
esac

case ... in
    (pattern_1)  ... ;;
    (pattern_2)  ... ;;
    (pattern_3|pattern_4) ... ;;
     *)  ... ;;
esac




반응형

'IoT 과정' 카테고리의 다른 글

Program Loops  (0) 2017.07.07
Shell Patterns  (0) 2017.07.07
Shell Arithmetic  (0) 2017.07.06
Designing Program Output  (0) 2017.07.06
User Input  (0) 2017.07.05