320
|
1 #!/bin/bash
|
|
2
|
|
3 # illustrate self-writing script (example)
|
321
|
4 # This one does something hard and replaces dynamic data with sed.
|
|
5 # Other solutions (magic markers, etc) are possible
|
320
|
6
|
321
|
7 path=`readlink -f $0`
|
|
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
|
322
|
15 # echo last and current generation times for example
|
|
16 echo "This script last generated at (None)"
|
|
17 echo "Now: ${datestamp}" |