IoT 과정
HPUX - Shell Programming - Loops
gaelim
2017. 6. 23. 16:31
반응형
Arithmetic Evaluation Using let
$ x=10
$ x=x+1
$ echo $x
x+1
$ x=10
$ let x=x+1 //let command enables shell scripts to use arithmetic expressions
$ echo $x
11
$ (( x=x+1 ))
$ echo $x
12
$ x=12
$ (( x>10 ))
$ echo $?
0
$ (( x<10 ))
$ echo $?
1
test - arithmetic evaluation, string, file
let - arithmetic evaluation, arithmetic operator
while
ans=yes
while [ "$ans" = yes ]
do
echo Enter a name
read name
echo $name >> file.names
echo "Continue?"
echo enter yes or no
read ans
done
$ vi sum_them
"sum_them" 10 lines, 139 characters
x=1
sum=0
while (( x <= $1 ))
do echo enter $x th num
read num
(( sum = sum + num))
let x=x+1
echo sum is $sum
done
echo total $sum
until
ans=yes
until [ "$ans" = no ]
do
echo Enter a name
read name
echo $name >> file.names
echo "Continue?"
echo enter yes or no
read ans
done
for
반응형