#!/bin/sh -u # $0 (no args) # A script that loops concatenating a string over and over until # the length of the output string is larger than a desired length. # # Some of the comments in this script are "teacher" comments that should # never appear in student programs (or real-world programs). # # -IAN! idallen@ncf.ca February 2002 export PATH=/bin:/usr/bin umask 022 # The string to repeat (quoted to include the blanks). # The desired length of the output, in characters. # string='Hello World! ' length=100 # Use command substitution to get the current length of the string. # The "wc" command is reading stdin, which is the output of the "echo". # The output of "wc" (the number) is substituted into the line. # The "test" command (named "[") tests the number against the length. # The return code of "test" determines whether the "while" keeps going. # out='' # start with an empty output string while [ $(echo "$out" | wc -c) -lt $length ]; do echo "The current length is $(echo "$out" | wc -c)" out="$out$string" echo "The new length is $(echo "$out" | wc -c)" done echo "The output string is:" echo "$out" echo "The length of the output string is: $(echo "$out" | wc -c)" exit 0