pure-bash-bible/manuscript/chapter12.txt

32 lines
456 B
Plaintext
Raw Permalink Normal View History

2018-06-23 02:34:15 +02:00
# ARITHMETIC
2018-06-23 02:34:15 +02:00
## Simpler syntax to set variables
2018-06-21 10:00:05 +02:00
```shell
2018-06-23 02:34:15 +02:00
# Simple math
((var=1+2))
2018-06-21 10:00:05 +02:00
2018-06-23 02:34:15 +02:00
# Decrement/Increment variable
((var++))
((var--))
((var+=1))
((var-=1))
2018-06-21 10:00:05 +02:00
2018-06-23 02:34:15 +02:00
# Using variables
((var=var2*arr[2]))
2018-06-21 10:00:05 +02:00
```
2018-06-23 02:34:15 +02:00
## Ternary Tests
```shell
2018-06-23 02:34:15 +02:00
# Set the value of var to var2 if var2 is greater than var.
# var: variable to set.
# var2>var: Condition to test.
# ?var2: If the test succeeds.
# :var: If the test fails.
((var=var2>var?var2:var))
```
<!-- CHAPTER END -->