# HG changeset patch # User Jeff Hammel # Date 1370705197 25200 # Node ID c64406cdcee101f3621263aaf2b963b43e290102 # Parent 5a0009051b1316a6a306f5453ca08ebec339e674 nearly works diff -r 5a0009051b13 -r c64406cdcee1 bin/example/self-writing.sh --- a/bin/example/self-writing.sh Sat Jun 08 07:33:06 2013 -0700 +++ b/bin/example/self-writing.sh Sat Jun 08 08:26:37 2013 -0700 @@ -1,6 +1,15 @@ #!/bin/bash # illustrate self-writing script (example) +# This one does something hard and replaces dynamic data with sed. +# Other solutions (magic markers, etc) are possible -path=`readlink $0` -tmp=`tempfile` \ No newline at end of file +path=`readlink -f $0` +tmp=`tempfile` +datestamp=`date` +nonce="This script regenerated at " + +# avoiding -i for safety +sed 's/\(echo \"'"${nonce}"'\).*\"/\1'"${datestamp}"'\"/' ${path} > ${tmp} + +echo "This script regenerated at " \ No newline at end of file