Cookbook: add an example of using default.do for text processing.
This commit is contained in:
parent
d663c9b67d
commit
3b305edc7e
18 changed files with 377 additions and 28 deletions
25
Documentation/cookbook/defaults/default.do
Normal file
25
Documentation/cookbook/defaults/default.do
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# $1 is the target name, eg. test.txt
|
||||
# $2 in the same as $1. We'll talk about
|
||||
# that in a later example.
|
||||
# $3 is the temporary output file we should
|
||||
# create. If this script is successful,
|
||||
# redo will atomically replace $1 with $3.
|
||||
|
||||
if [ -e "$1.in" ]; then
|
||||
# if a .in file exists, then do some
|
||||
# text substitution.
|
||||
#
|
||||
# Remember, the user asks redo to build
|
||||
# a particular *target* name. It's the .do
|
||||
# file's job to figure out what source file(s)
|
||||
# to use to generate the target.
|
||||
redo-ifchange "$1.in" version date
|
||||
read VERSION <version
|
||||
read DATE <date
|
||||
sed -e "s/%VERSION%/$VERSION/g" \
|
||||
-e "s/%DATE%/$DATE/g" \
|
||||
<$1.in >$3
|
||||
else
|
||||
echo "$0: Fatal: don't know how to build '$1'" >&2
|
||||
exit 99
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue