Homework assistance
#!/bin/bash
clear
BORDER=$(printf '=%.0s' {1..80})\\n
HEADER="%-10s %8s %-10s %24s %11s\n"
FORMAT="%-10s %8d %-10s %11.2f\n"
WIDTH=150
# not defined, what should this be?
# DIVIDER="DIVIDER"
OUTPUT_FILENAME=experimentation.csv
# delete the file if it exists
[ -f "$OUTPUT_FILENAME" ] && rm $OUTPUT_FILENAME
# write header to file
printf "$BORDER" | tee -a $OUTPUT_FILENAME
printf "$HEADER" "SORT NUM" "2^n" "Output" "Elapsed Time" | tee -a $OUTPUT_FILENAME
printf "%$WIDTH.${WIDTH}s\n" "$DIVIDER" | tee -a $OUTPUT_FILENAME
for x in {1..5}; do
for n in {4..12}; do
exponent=$((2**n))
# save output from 'my_sort' so it can be written to file
result="$(./my_sort $x $n)"
REPLACE_ME=$(((RANDOM % 10) + 100))
printf "$FORMAT" "$x" "$n" "$result" "$REPLACE_ME" | tee -a $OUTPUT_FILENAME
done
done
# Example output:
# SORT NUM 2^n Output Elapsed Time
# 1 4 output-from-process 108.00
# 1 5 output-from-process 107.00
# 1 6 output-from-process 101.00
# 1 7 output-from-process 105.00
# 1 8 output-from-process 106.00
# 1 9 output-from-process 106.00
# 1 10 output-from-process 101.00