1 minute read

adv expression

parentheses, braces, brackets

![[no-alignment]](https://happyobo.github.io/assets/Linux/pbb.png){: .align-center}

```s
obo@obo-900X3L:~/Github/happyOBO.github.io$ a=13
obo@obo-900X3L:~/Github/happyOBO.github.io$ p=$(($a+12))
obo@obo-900X3L:~/Github/happyOBO.github.io$ echo $p
25

obo@obo-900X3L:~/Github/happyOBO.github.io$ a1b=1
obo@obo-900X3L:~/Github/happyOBO.github.io$ a2b=2
obo@obo-900X3L:~/Github/happyOBO.github.io$ a3b=3
obo@obo-900X3L:~/Github/happyOBO.github.io$ echo $a{1,2,3}b
1 2 3
```

bash에서 integer 연산할 때

  • range of bash integer : 62bit long integer
  • real number
    • bash는 floating point를 인식하지 못한다.
    • dot(.)이 등장하면 문자열로 인식하게된다.
  • 수치 연산 비교

    [no-alignment]

    [no-alignment]

      obo@obo-900X3L:~$ cat arith.sh 
      #! /bin/bash
      let "vone = 3, vtwo = 4"
      let "vthree = vone * vtwo + 1"
      echo vthree = $vthree
      let "vfour = vthree / 3"
      echo vfour = $vfour
      (( $vone + $vthree + 10 > 20 ))
      if [ $? = 0 ]; then
      echo "True (greater than 20)"
      fi
      (( (vfive = ($vone + $vthree + 10)) > 20 )) && echo "$vfive gt 20"
      obo@obo-900X3L:~$ ./arith.sh 
      vthree = 13
      vfour = 4
      True (greater than 20)
      26 gt 20
    

진수법

  • 숫자 앞이 0으로 시작하면 8진수로 약속 0x 는 16진수..!
$ ioct=064
$ ihex=0x64
$ ibin=2#10110111
$ ib64=64#1Ab@
$ echo "oct($ioct) hex($ihex) bin($ibin) base64($ib64)"
oct(064) hex(0x64) bin(2#10110111) base64(64#1Ab@)

for문 예제

for ((i=0, sum=0; i<=10000; i++))
do
    (( sum+=i ))
done
echo $sum
i=0
while (( i < 10))
do
    (( i+=3 ))
done
echo $i
steven_job="programmer"
mick_job="director"
kenny_job="designer"
tensun_job="programmer"
for iter in {steven,mick,Kenny,tensun}_job
do
    echo $iter
done
for iter in {0..10}
do
    echo $iter
done

Categories:

Updated: