1#! /bin/bash 2# 3# original from: 4# @(#) uuenc.ksh 1.0 93/09/18 5# 93/09/18 john h. dubois iii (john@armory.com) 6# 7# conversion to bash v2 syntax by Chet Ramey 8 9istrue() 10{ 11 test 0 -ne "$1" 12} 13 14isfalse() 15{ 16 test 0 -eq "$1" 17} 18 19phelp() 20{ 21echo "$name: uuencode files. 22$Usage 23For each filename given, $name uuencodes the file, using the final 24component of the file's path as the stored filename in the uuencoded 25archive and, with a .${SUF} appended, as the name to store the archive in. 26Example: 27$name /tmp/foo 28The file /tmp/foo is uuencoded, with \"foo\" stored as the name to uudecode 29the file into, and the output is stored in a file in the current directory 30with the name \"foo.${SUF}\". 31Options: 32-f: Normally, if the file the output would be stored in already exists, 33 it is not overwritten and an error message is printed. If -f (force) 34 is given, it is silently overwritten. 35-h: Print this help." 36} 37 38name=${0##*/} 39Usage="Usage: $name [-hf] <filename> ..." 40typeset -i force=0 41 42SUF=uu 43 44while getopts :hf opt; do 45 case $opt in 46 h) phelp; exit 0;; 47 f) force=1;; 48 +?) echo "$name: options should not be preceded by a '+'." 1>&2 ; exit 2;; 49 ?) echo "$name: $OPTARG: bad option. Use -h for help." 1>&2 ; exit 2;; 50 esac 51done 52 53# remove args that were options 54shift $((OPTIND - 1)) 55 56if [ $# -lt 1 ]; then 57 echo "$Usage\nUse -h for help." 1>&2 58 exit 59fi 60 61for file; do 62 tail=${file##*/} 63 out="$tail.${SUF}" 64 if isfalse $force && [ -a "$out" ]; then 65 echo "$name: $out: file exists. Use -f to overwrite." 1>&2 66 else 67 uuencode $file $tail > $out 68 fi 69done 70