initial commit
This commit is contained in:
10
chapter4/function_dots
Executable file
10
chapter4/function_dots
Executable file
@@ -0,0 +1,10 @@
|
||||
function dots
|
||||
{
|
||||
SEC=$1 # How many seconds between dots?
|
||||
|
||||
while true
|
||||
do
|
||||
sleep $SEC
|
||||
echo ".\c"
|
||||
done
|
||||
}
|
||||
10
chapter4/function_elapsed_time
Executable file
10
chapter4/function_elapsed_time
Executable file
@@ -0,0 +1,10 @@
|
||||
elasped_time ()
|
||||
{
|
||||
SEC=$1
|
||||
(( SEC < 60 )) && $ECHO "[Elasped time: $SEC seconds]\c"
|
||||
|
||||
(( SEC >= 60 && SEC < 3600 )) && $ECHO "[Elasped time: $(( SEC / 60 )) min $(( SEC % 60 )) sec]\c"
|
||||
|
||||
(( SEC > 3600 )) && $ECHO "[Elasped time: $(( SEC / 3600 )) hr $(( (SEC % 3600) / 60 )) min $(( (SEC % 3600) % 60 )) sec]\c"
|
||||
}
|
||||
|
||||
46
chapter4/function_rotate
Executable file
46
chapter4/function_rotate
Executable file
@@ -0,0 +1,46 @@
|
||||
function rotate
|
||||
{
|
||||
# PURPOSE: This function is used to give the end user
|
||||
# some feedback that "something" is running. It gives
|
||||
# a line rotating in a circle. This function is started
|
||||
# as a background process. Assign its PID to a variable
|
||||
# using
|
||||
# rotate & # To start
|
||||
# ROTATE_PID=$! # Get the PID of the last
|
||||
# # background job
|
||||
#
|
||||
# At the end of execution just break out by
|
||||
# killing the $ROTATE_PID process. We also need
|
||||
# to do a quick "cleanup" of the leftover line of
|
||||
# rotate output.
|
||||
#
|
||||
# FROM THE SCRIPT:
|
||||
# kill -9 $ROTATE_PID
|
||||
# echo "\b\b "
|
||||
|
||||
INTERVAL=1 # Sleep time between rotation intervals
|
||||
RCOUNT="0" # For each RCOUNT the line rotates 1/8
|
||||
# cycle
|
||||
|
||||
while : # Loop forever...until this function is killed
|
||||
do
|
||||
(( RCOUNT = RCOUNT + 1 )) # Increment the RCOUNT
|
||||
|
||||
case $RCOUNT in
|
||||
1) echo .-."\b\c"
|
||||
sleep $INTERVAL
|
||||
;;
|
||||
2) echo .\\."\b\c"
|
||||
sleep $INTERVAL
|
||||
;;
|
||||
3) echo "|\b\c"
|
||||
sleep $INTERVAL
|
||||
;;
|
||||
4) echo "/\b\c"
|
||||
sleep $INTERVAL
|
||||
;;
|
||||
*) RCOUNT="0" # Reset the RCOUNT to "0", zero.
|
||||
;;
|
||||
esac
|
||||
done
|
||||
} # End of Function - rotate
|
||||
36
chapter4/timing_test_function.bash
Executable file
36
chapter4/timing_test_function.bash
Executable file
@@ -0,0 +1,36 @@
|
||||
#!/bin/bash
|
||||
|
||||
# SCRIPT: timing_test_function.bash
|
||||
# AUTHOR: Randy Michael
|
||||
|
||||
######## DEFINE VARIABLES HERE ########
|
||||
|
||||
# Ready script for ksh or bash
|
||||
ECHO=echo
|
||||
[[ $(basename $SHELL) == bash ]] && ECHO="echo -e"
|
||||
|
||||
|
||||
elasped_time ()
|
||||
{
|
||||
SEC=$1
|
||||
(( SEC < 60 )) && $ECHO "[Elasped time: $SEC seconds]\c"
|
||||
|
||||
(( SEC >= 60 && SEC < 3600 )) && $ECHO "[Elasped time: $(( SEC / 60 )) min $(( SEC % 60 )) sec]\c"
|
||||
|
||||
(( SEC > 3600 )) && $ECHO "[Elasped time: $(( SEC / 3600 )) hr $(( (SEC % 3600) / 60 )) min $(( (SEC % 3600) % 60 )) sec]\c"
|
||||
}
|
||||
|
||||
###### BEGINNING OF MAIN
|
||||
|
||||
SECONDS=15
|
||||
elasped_time $SECONDS
|
||||
$ECHO
|
||||
SECONDS=60
|
||||
elasped_time $SECONDS
|
||||
$ECHO
|
||||
SECONDS=3844
|
||||
elasped_time $SECONDS
|
||||
$ECHO
|
||||
sleep 10
|
||||
elasped_time $SECONDS
|
||||
$ECHO
|
||||
Reference in New Issue
Block a user