blob: 8c8ffe3e274386e752861bc41361694e6073a586 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#!/bin/dash
TO_UPPER=""
TO_LOWER=""
PREFIX=
SUFFIX=
FILTER_VOWELS=""
ARGC=0
usage() {
cat << EOF
usage: $0 [-luvh] [-p prefix] [-s suffix] [inputs...]
options:
-l convert inputs to lowercase
-u convert inputs to uppercase
-v remove vowels from inputs
-h show help
-p prefix add \`prefix\` to each line before inputs
-s suffix add \`suffix\` to each line after inputs
notes:
if -l and -u are specified at the same time, the lowercase option will have
precedence
EOF
exit $1
}
while getopts dulhp:s:v OPT; do
[ $OPTIND -gt $ARGC ] && ARGC=$OPTIND
case $OPT in
u) TO_UPPER="y" ;;
l) TO_LOWER="y" ;;
h) usage 0 ;;
p) PREFIX=$OPTARG ;;
s) SUFFIX=$OPTARG ;;
v) FILTER_VOWELS="y" ;;
\?|*) usage 1 ;;
esac
done
[ $(( $# - $ARGC )) -lt 0 ] && echo "please provide some input" && usage 1
shift $(( ARGC - 1 ))
while [ -n "$1" ]; do
OUT="$1"
[ -n "$TO_UPPER" ] && OUT="`echo "$OUT" | sed 's/./\U\0/g'`"
[ -n "$TO_LOWER" ] && OUT="`echo "$OUT" | sed 's/./\L\0/g'`"
[ -n "$FILTER_VOWELS" ] && OUT="`echo "$OUT" | sed 's/[aeuio]//g'`"
echo "$PREFIX$OUT$SUFFIX"
shift
done
|