#!/bin/sh # Copyright (C) 2003 Adalbert Prokop, adalbert.prokop(%)web.de # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ROT13="$(basename "$0")" function showhelp() { cat <<+++ NAME $ROT13 - codes a textline, file or standard input by shifting all letters 13 positions to the right. SYNOPSIS $ROT13 [-i inputfile] [-o outputfile] [-h] [text] DESCRIPTION inputfile: file to encode in rot13. outputfile: file, where the output will be written to -h: gives this help text: if no inputfile is specified, _text_ will be coded with rot13. If not given, the STD_IN will be coded If the outputfile is not specified, the STD_OUT will be use +++ } INPUTFILE= OUTPUTFILE= ABC=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ CBA=nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM # eval: to get rid of those damned single quotes eval set -- $(getopt -o hi:o: -n "$ROT13" -l help -- "$@") while [ "$1" != "--" ]; do case "$1" in -h|--help) showhelp; exit 0;; -i) INPUTFILE=$2; shift 2;; -o) OUTPUTFILE=$2; shift 2;; esac done shift # kill "--" if [ "$INPUTFILE" ]; then INPUT="cat $INPUTFILE" elif [ "$*" ]; then INPUT="echo \"$*\"" else INPUT="cat" fi if [ "$OUTPUTFILE" ]; then OUTPUT=">$OUTPUTFILE" else OUTPUT= fi eval $INPUT| eval tr "$ABC" "$CBA" $OUTPUT