Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'Track changes made with the defaults command' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Track changes made with the defaults command
Authored by: dgerrity on Aug 29, '11 11:50:04AM
An improvement on the log function and an answer to my own question about logging multi-line output For the log function, I indent with shell levels so you can see in the log when scripts call other scripts; also, because $0 is often "-bash" and the dash is interpreted as an option, I strip a leading dash from the name of the calling function.

log () {
    sp=$(printf "%$(((${SHLVL}-1)*4))s" " ");
    echo "$(date "+%Y-%m-%d %H:%M:%S")${sp}$(echo $0 | sed 's/^-//') $@" >> "${lf}"
And secondly, a way to put multiple lines into the log (duh):

port list installed | while read line; do log $line; done

[ Reply to This | # ]