-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter.sh
47 lines (40 loc) · 958 Bytes
/
filter.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
#!/bin/sh
#
# Copyright (c) 2000-2014 Matthew Pearson <[email protected]>.
#
# These scripts are free. There is no warranty; your mileage may vary.
# Visit http://creativecommons.org/licenses/by-nc-sa/4.0/ for more details.
#
# $Id$
# replaces vars in dotfiles and scripts with their assigned values
#
PATH=. # for sourcing from current directory
if [ $# -eq 2 ]
then
[ -f $1 ] && [ -f $2 ] || exit 1
conf1=$1
conf2=""
ffile=$2
. $conf1
elif [ $# -eq 3 ]
then
[ -f $1 ] && [ -f $2 ] && [ -f $3 ] || exit 1
conf1=$1
conf2=$2
ffile=$3
. $conf1
. $conf2
else
exit 1
fi
PATH=/usr/xpg4/bin:/bin:/usr/bin
# promote ksh scripts to bash if ksh is not available
[ -x /bin/ksh ] || sedexp="-e 's|^#!/bin/ksh|#!/bin/bash|g'"
for var in `sed -n '/^[A-Z_]*=/p' $conf1 $conf2 | sed 's/=.*//'`
do
left=$var
right=`eval echo '$'${var}`
sedexp=${sedexp:+"$sedexp "}"-e 's|__${left}__|${right}|g'"
done
eval sed ${sedexp} ./$ffile
#EOF __TAGGED__