-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixit.sh
executable file
·52 lines (48 loc) · 1.11 KB
/
fixit.sh
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
#!/usr/bin/env sh
#: A template for making a change to a group of files,
#: previewing each change before it is made.
force=
#bflag=
while getopts ab: name
do
case $name in
a) force=1;;
# b) bflag=1
# bval="$OPTARG";;
?) printf "Usage: %s: [-a] [-b value] args\n" $0
exit 2;;
esac
done
if [ ! -z "$force" ]; then
printf "Option -a specified\n"
fi
if [ ! -z "$bflag" ]; then
printf 'Option -b "%s" specified\n' "$bval"
fi
#shift $(($OPTIND - 1))
#printf "Remaining arguments are: %s\n" "$*"
for file in `ls *.html`
do
echo Editing $file
sed 's/aaaaa/bbbbb/' $file > $file.new
diff $file $file.new
result=$?
if [ $result -gt 0 ] ; then
if [ ! -z "$force" ]; then
answer="y"
else
read -p "ok (y/n/A) " answer
echo "answer=" $answer
if [ "$answer" = "A" ] ; then
force=1
fi
fi
if [ "$answer" = "y" ] ; then
mv -f $file $file.backup
mv -f $file.new $file
echo File replaced
fi
else
rm $file.new
fi
done