This version seems cleaner and clearer than the previous version, so
is more likely to be correct.
Signed-off-by: Martin Schwenke <martin@meltin.net>
instring="$1"
delimiter="${2:-@@}"
- # get the list of variables used in the template
- VARS=`echo "$instring" |
- tr -cs "A-Z0-9_$delimiter" '\012' |
- sort -u |
- sed -e "s#@@*[^@]*@@*#&\n#" |
- sed -n -e "s#^[^@]*${delimiter}\(.*\)${delimiter}[^@]*\\$#\1#p"`
+ # Get the list of variables used in the template. The grep
+ # gets rid of any blank lines and lines with extraneous '@'s
+ # next to template substitutions.
+ VARS=$(echo "$instring" |
+ sed -n -e "s#[^@]*${delimiter}\([A-Z0-9_][A-Z0-9_]*\)${delimiter}[^@]*#\1\n#gp" |
+ grep '^[A-Z0-9_][A-Z0-9_]*$' |
+ sort -u)
tmp=$(mktemp)
for v in $VARS; do