Korn Shell: Unix and Linux Programming Manual, Third Edition, The By Anatole Olczak
Table of Contents
Appendix D. Sample Korn Shell Scripts
Interactive uucp - kuucp
Here is an interactive version of the uucp command. Instead of looking for a system name in the uucp systems file using grep, the remote system name is verified by using file I/O substitution and Korn shell patterns.
#!/bin/ksh## kuucp - Korn shell interactive uucp## Check usageif (($# > 0))thenprint "Usage: $0"exit 1fi# Set variablesPUBDIR=${PUBDIR:-/usr/spool/uucpublic}# This sets UUSYS to the contents of the HDB-UUCP# Systems file. It may be different on your system.UUSYS=$(</usr/lib/uucp/Systems)# Get source fileread SOURCE?"Enter source file: "# Check source fileif [[ ! -f $SOURCE ]]thenprint "$SOURCE: non-existent or not accessible"exit 2fi# Get remote system nameread RSYS?"Enter remote system name: "# Check remote system name. It looks for a pattern# match on the system name in the UUSYS file## For the Bourne shell or older versions# of Korn shell, this could be given as:# if [[ $(grep ^$RSYS $UUSYS) != "" ]]if [[ $UUSYS != *$RSYS* ]]thenprint "$RSYS: Invalid system name"exit 2fiprint "Copying $SOURCE to $RSYS!$PUBDIR/$SOURCE"uucp $SOURCE $RSYS!$PUBDIR/$SOURCE