variable(){
declare string="a b"; echo "$string"
declare -i int=21; echo "$(( int * 2 ))"
declare -a array=(a "b c"); for string in "${array[@]}"; do echo "$string"; done
declare -A dict=([a]="b c" ["d e"]=f); for key in "${!dict[@]}"; do echo "$key: ${dict[$key]}"; done
}
condiction(){
if true; then
echo as simple as that
fi
if (( 1 > 1)); then echo no
elif [[ "$a" == toto ]]; then echo no
elif true; then echo yes
else echo no
fi
}
loop(){
for string in a "b c"; do
echo "$string"
done
while :; do echo "$((i++))"; done
}
func(){
func(){
for i; do echo "$((j++)): $i|"; done
}
func a "b c"
}
switch(){
while [[ "$#" -gt 0 ]]; do
case $1 in
--ant) antenna=$2; shift;;
-v) verbose=1;;
*) echo "unknown argument";;
esac
shift
done
echo "antenna:$antenna, verbose:$verbose"
}
redirection(){
exec 3<> /tmp/file
echo value >&3
cat <&3
exec 3>&-
}
compgen -c | grep -i corr
echo "${PATH//:/$'\n'}"
string=$(<file.txt)
exec {fd}>&1
out=$(echo toto | tee "/dev/fd/$fd")
exec {fd}>&-
echo "$out"
declare -A d_pid=() d_fd=() d_ret=() d_out=()
for id in {0..9}; do
eval "exec {fd}< <(echo message$id)"; d_pid[$id]=$!; d_fd[$id]=$fd
done
for id in "${!d_pid[@]}"; do
wait "${d_pid[$id]}"; d_ret[$id]=$?
d_out[$id]=$(cat <&"${d_fd[$id]}")
done
for id in "${!d_pid[@]}"; do
printf '| %-3s | %-3s | %-6s | %-2s | %s |\n' "$id" "${d_fd[$id]}" "${d_pid[$id]}" "${d_ret[$id]}" "${d_out[$id]}"
done