#!/bin/bash # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Copyright (c) 2010 FSOCA final project | http://joaosantacruz.com # This script is licensed under GNU GPL version 2.0 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Create a BASH script (bartsimpson.sh) that asks for a phrase such as ÒI will not # make my computer go through endless loopsÓ that then iterates 100 times and outputs # the 100 phrases to a file chalkboard.dat. # Extension: Use a for loop, while loop and if loop to generate the same output. # Name the scripts bartsimpson-for.sh, bartsimpson-while.sh, bartsimpson-if.sh # that output to chalkboard-for.dat, chalkboard-while.dat and chalkboard-if.dat. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - clear echo "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =" echo " BartSimpson - for " echo "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =" echo "" time1=`date +%s` loops=1000 filename="chalkboard-for.dat" mystring="" phrase="I will not make my computer go through endless loops." for (( i = 0 ; i < $loops; i++ )) do mystring="$mystring $phrase" done time2=`date +%s` exectime=`expr $time2 - $time1` echo $mystring > $filename echo "Bart wrote 'I will not make my computer go through endless loops.' $i times!" echo "Logfile: $filename" echo "Execution time: $exectime s (using for loop)" echo "" echo "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =" echo "Press [enter] key to continue. . ."; read pressedKey