#!/opt/pware/bin/bash # # This loop prints the integer strings in the given set # for x in 0 1 2 3 4 5 6 7 8 9 do echo $x done # # This loop prints integers on the same line as a form of progress meter. # This is done using -e (enable escape sequences), -n (disable newline) # and the \r to indicate carriage return and overwrite previous output. # for x in 0 1 2 3 4 5 6 7 8 9 do echo -e -n "$x\r" # sleep 1 done # # This loop prints strings and enforces the use of double quotes # for x in "the quick" "brown fox" "jumps over the" "lazy dog" do echo $x done # # While loop to demonstrate use of integer variable with let and (( )) # Note the lack of the "$" dereferencing character. # #let x=0 while (( x < 10 )) do (( x++ )) done # # if test to check for existence of a file. if exists, count lines # if [ -a ex1.bash ]]; then wc -l fi # # Use ps output as input to while look using read command. x vars are ignored. # demonstrates use of many forms of quoting. Also uses escapes in echo. # ps awwx | while read pid x x time cmd do echo -e "The Command \"$cmd\"\nhas been running for $time" echo "and has PID = $pid" done # # Function to calculate a substring using "cut" and the arguments: # "string-value" start-column end-column # # This also uses a "here-document" for use with cut. # function substring { # # debug statements # #echo "\$1 = \"$1\"" #echo "\$2 = \"$2\"" #echo "\$3 = \"$3\"" cut -c$2-$3 <