Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame^] | 1 | #!/bin/sh |
| 2 | |
| 3 | |
| 4 | if [ $# -lt 2 ]; then |
| 5 | echo "usage: substitute.sh <variable to replace> <value to replace with> <filename | STDIN>" |
| 6 | exit 1 |
| 7 | fi |
| 8 | |
| 9 | if [ $# -eq 3 ]; then |
| 10 | VARIABLE=$1 |
| 11 | VALUE=$2 |
| 12 | FILENAME=$3 |
| 13 | |
| 14 | echo "replacing $VARIABLE with $VALUE in $FILENAME" |
| 15 | sed -e "s/$VARIABLE/$VALUE/" $FILENAME > "$FILENAME"_tmp |
| 16 | mv "$FILENAME"_tmp $FILENAME |
| 17 | exit 0 |
| 18 | fi |
| 19 | |
| 20 | if [ $# -eq 2 ]; then |
| 21 | while read line; |
| 22 | do |
| 23 | VARIABLE=$1 |
| 24 | VALUE=$2 |
| 25 | FILENAME=${line} |
| 26 | |
| 27 | echo "replacing $VARIABLE with $VALUE in $FILENAME" |
| 28 | sed -e "s/$VARIABLE/$VALUE/" $FILENAME > "$FILENAME"_tmp |
| 29 | mv "$FILENAME"_tmp $FILENAME |
| 30 | done |
| 31 | exit 0 |
| 32 | fi |
| 33 | |