Wednesday, May 18, 2005

Howto Use Commands Within echo

Here's a new trick I learned yesterday. You can execute a command within an echo statement by enclosing the command in backwards quotes, and enclosing the echo arguments within double quotes. Example:
    echo "Current time: `date`"
In the past, I'd always done this as two lines. The first would capture the output of the command into a variable and the second would print the results using echo. Example:
    dt=`date`
    echo "Current time: $dt"
Granted, this is not break-through technology, but every incremental advancement gets me closer to world domination. Did I say that out loud?

No comments:

Post a Comment