#! /bin/bash
istrue()
{
test 0 -ne "$1"
}
isfalse()
{
test 0 -eq "$1"
}
phelp()
{
echo "$name: uuencode files.
$Usage
For each filename given, $name uuencodes the file, using the final
component of the file's path as the stored filename in the uuencoded
archive and, with a .${SUF} appended, as the name to store the archive in.
Example:
$name /tmp/foo
The file /tmp/foo is uuencoded, with \"foo\" stored as the name to uudecode
the file into, and the output is stored in a file in the current directory
with the name \"foo.${SUF}\".
Options:
-f: Normally, if the file the output would be stored in already exists,
it is not overwritten and an error message is printed. If -f (force)
is given, it is silently overwritten.
-h: Print this help."
}
name=${0Usage="Usage: $name [-hf] <filename> ..."
typeset -i force=0
SUF=uu
while getopts :hf opt; do
case $opt in
h) phelp; exit 0;;
f) force=1;;
+?) echo "$name: options should not be preceded by a '+'." 1>&2 ; exit 2;;
?) echo "$name: $OPTARG: bad option. Use -h for help." 1>&2 ; exit 2;;
esac
done
shift $((OPTIND - 1))
if [ $ echo "$Usage\nUse -h for help." 1>&2
exit
fi
for file; do
tail=${file out="$tail.${SUF}"
if isfalse $force && [ -a "$out" ]; then
echo "$name: $out: file exists. Use -f to overwrite." 1>&2
else
uuencode $file $tail > $out
fi
done