aboutsummaryrefslogtreecommitdiffstats
path: root/examples/scripts.v2/uuenc
diff options
context:
space:
mode:
Diffstat (limited to 'examples/scripts.v2/uuenc')
-rw-r--r--examples/scripts.v2/uuenc69
1 files changed, 69 insertions, 0 deletions
diff --git a/examples/scripts.v2/uuenc b/examples/scripts.v2/uuenc
new file mode 100644
index 0000000..480aa48
--- /dev/null
+++ b/examples/scripts.v2/uuenc
@@ -0,0 +1,69 @@
+#! /bin/bash
+#
+# original from:
+# @(#) uuenc.ksh 1.0 93/09/18
+# 93/09/18 john h. dubois iii (john@armory.com)
+#
+# conversion to bash v2 syntax by Chet Ramey
+
+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=${0##*/}
+Usage="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
+
+# remove args that were options
+shift $((OPTIND - 1))
+
+if [ $# -lt 1 ]; then
+ 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