Presented by Died R. June 21, 2019
Sequence, selection and Iteration: https://en.wikipedia.org/wiki/Structured_programming#Theoretical_foundation
- Sequence
- Ordered statements
- a = b * 3
- print “stuff”
- foo = sin(3)
- Ordered statements
- Selection
- Choose one or another set of statements
- if i = 7 then
- do something
- else
- do something else or perhaps nothing
- do something else or perhaps nothing
- if i = 7 then
- Choose one or another set of statements
- Iteration
- Do a set of statements repeatedly
- while i > 92 do things :
- while i > 92 do things :
- Do a set of statements repeatedly
#! /bin/bash
# Structured programming
## https://en.wikipedia.org/wiki/Structured_programming#Theoretical_foundation#! /bin/bash
# sequence
a=5
b=3
echo $a
echo $b
echo $((a + b))
declare -i c;
c=”5 + 4″
echo “$c”
c=$c+1
echo “$c”
## parameters
echo “$1” “$2”
echo ———————–
#! /bin/bash
# selection
## about [
if [ “$1” = ‘foo’ ]; then
echo you have foo
else
echo you are fooless
echo but you have “$1” and “$2”
fi
if [ -e “$2” ]; then
echo the file “$2” exists
else
echo the file “$2” does not exist here.
fi
echo ———————————–
#! /usr/bin/env bash
# iteration
## about let https://www.computerhope.com/unix/bash/let.htm
n=0
m=$1
while [ $n -lt “$m” ]; do
echo $n
let n=n+1
done