comparison bin/example/self-writing.sh @ 321:c64406cdcee1

nearly works
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 08 Jun 2013 08:26:37 -0700
parents 5a0009051b13
children 19b5bf66ba4e
comparison
equal deleted inserted replaced
320:5a0009051b13 321:c64406cdcee1
1 #!/bin/bash 1 #!/bin/bash
2 2
3 # illustrate self-writing script (example) 3 # illustrate self-writing script (example)
4 # This one does something hard and replaces dynamic data with sed.
5 # Other solutions (magic markers, etc) are possible
4 6
5 path=`readlink $0` 7 path=`readlink -f $0`
6 tmp=`tempfile` 8 tmp=`tempfile`
9 datestamp=`date`
10 nonce="This script regenerated at "
11
12 # avoiding -i for safety
13 sed 's/\(echo \"'"${nonce}"'\).*\"/\1'"${datestamp}"'\"/' ${path} > ${tmp}
14
15 echo "This script regenerated at "