~johanvandegriff/unix-shell-programming-revised-edition-programs

unix-shell-programming-revised-edition-programs/code/encode.sh -rw-r--r-- 426 bytes
fc214385Johan Vandegriff added other old scripts, some newer ones too 2 years ago
                                                                                
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
#!/bin/bash
file="$1"
letters="$2"
codeletters="$3"
outfile="$4"

if [ "$#" -eq "0" ]
then
  echo "usage: $0 (input file) (letters to change) (letters to change to) [output file]"
  exit 1
fi

if [ ! -f "$file" ]
then
  echo "$file does not exist or is not a normal file."
  exit 1
fi

message=`cat "$file" | tr "$letters" "$codeletters"`

if [ "$outfile" == "" ]
then
  echo "$message"
else
  echo "$message" > "$outfile"
fi