To turn the "functions in" chapter into a "library for", "scripts, extract all the functions and Concatenat e them into one of the big file. If We call this file library.sh, a test script so accesses all of the functions might look like this:
#!/bin/sh
# Library test script
. library.sh
initializeansi
Echon "" A, do you have echo in your pat H? (1=yes, 2=no) "
read answer while
! Validint $answer 1 2; Do
Echon "${boldon}try Again${boldoff}. Do your have echo "
Echon" in your path? (1=yes, 2=no) "
read answer
done
if!" Checkforcmdinpath "echo"; Then
echo "Nope, can ' t find the echo command."
else
echo "The echo command is in the PATH."
Fi
echo ""
Echon "Enter a year for you to might is a leap year:" Read the Year while
! Validint $year 1 9999; Do
Echon ' Please enter a year in the ${boldon}correct${boldoff} format: '
read year
did
if Isleapyea R $year; Then
echo "${greenf}you ' re right! $year is a leap year.${reset} "
else
echo" ${redf}nope, that's not a leap year.${reset} "
fi
exit 0
Application function, we can reuse our script.
It's worth noting that $. Tinyscript.sh is executing the script under the current shell without the "." or source
The script is executed under the sub shell, and there may be different occurrences, which are noteworthy.