User Tools

Site Tools


bash

Table of Contents

Bash Stuff

Substitution

Stdin

  • Dump stdin

#!/bin/bash
less <&0

  • Loop over stdin

#!/bin/bash
while read line; do
    echo ${line}
done <&0

Arrays

#!/bin/bash
# -*- mode: bash-script; -*-

dt=( 0.2 0.6 1.0 1.4 1.8 2.2 ) # days

echo ${dt[0]}
echo ${dt[1]}
echo ${dt[2]}
echo ${dt[3]}

echo "*** Loop over elements only"

for i in "${dt[@]}"; do
    echo $i
done

echo "*** Loop with indices"

for i in "${!dt[@]}"; do
    printf "%s - %s\n" "$i" "${dt[$i]}"
    dt[$i]=`bc <<< "scale=6; ${dt[$i]}/365" | sed 's/^\./0./`
    printf "%s - %s\n" "$i" "${dt[$i]}"
done

bash.txt · Last modified: 2017/07/31 12:56 by Volker