티스토리 뷰
Return Codes
The shell variable ? holds the return code of the last command executed
{
$ echo $?
1
$ adf
sh: adf: not found.
$ echot $?
sh: echot: not found.
$ echo $?
127
$ false
$ echo $?
1
$ echo $?
test command
test command can evaluate the condition of Integers, Strings, Files [조심! 실습파일은 test 말고 test.sh 등으로 작성, sh는 쉘을 의미]
test - Numeric Test
-lt, -le, -gt, -ge, -eq, -ne (less, less or equal, greater, greater or equal, equal, not equal]
{
$ test 10 -gt 5
$ echo $?
0
$ test 10 -lt 5
$ echo $?
1
test - String Test
test str1=str2, str1!=str2
{
$ x=yes
$ [ $x = yes ]
$ echo $?
0
$ [ $x != yes ]
$ echo $?
1
test - File Test
test -f filename or dirname, -d filename or dirname (-f file?, -d directory?, -r readable? -w writable? -x exist and executable?)
test - Other Operator
-o OR, -a AND, ! NOT, \( \) GROUPING
exit - return code of the last command
$ cat exit_test
echo exiting program now
exit 99
$ exit_test
exiting program now
$ echo $?
99
if
if [ $x -lt 10 ]
then echo String 1
fi
if-else
if [ $x -lt 10 ]
then echo String 1
else then echo String 2
fi
if [ $x -lt 10 ]
then echo String 1
else
if [ $x -gt 5 ]
then echo String 2
else echo String 3
fi
fi
elif
if [ $x -lt 10 ]
then echo String 1
elif [ $x -gt 5 ]
then echo String2
else echo String3
fi
case
case $ANS in
yes) echo O.K.
;; //break;
no) echo no go
;;
*) echo keep trying
;;
esac
$ vi menu_with_case
"menu_with_case" [New file]
echo type d date, w who, l ls
read choice
case $choice in
[dD]*) date ;;
[wW]*) who ;;
l*|L*) ls ;;
*) echo invalid ;;
esac
{
$ vi m16_9.sh
echo display current directory? [yes or no]
read ANS
if [ "$ANS" = yes ]
then echo $(pwd) | ls
elif [ "$ANS" = no ]
then echo what directory would you like to see?
read ANS
if [ -d $ANS ]
then cd $ANS
else
echo directory doesn\'t exist
fi
fi
'IoT 과정' 카테고리의 다른 글
HPUX - Managing Users and Groups (0) | 2017.06.26 |
---|---|
HPUX - Shell Programming - Loops (0) | 2017.06.23 |
HPUX - Shell Programming (0) | 2017.06.23 |
HPUX - Process Control (0) | 2017.06.22 |
HPUX - Pipes (0) | 2017.06.22 |
- Total
- Today
- Yesterday
- Discrete Mathematics
- 대규모 시스템 설계 기초
- Arena
- arena simulation
- 자바스크립트
- 시뮬레이션
- 자바스크립트 예제
- grafana cloud
- 데이터 중심 애플리케이션 설계
- Simulation
- 로젠
- 항해99
- 그라파나
- 최단경로 알고리즘
- 엄청난 인내심과 시뮬레이션을 위한 아레나 툴
- 가상 면접 사례로 배우는 대규모 시스템 설계 기초
- beginning javascript
- 명제논리
- 이산수학
- javascript
- rosen
- 백준
- 아레나 시뮬레이션
- 아레나시뮬레이션
- 이산 수학
- Propositional and Predicate Logic
- 아레나
- paul wilton
- Grafana
- flutter
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |