Those %
codes aren't processed by the shell, they're processed by date
, and perhaps some other things -- as Seamus observed, they come from the POSIX C command strftime()
, which almost certainly is in the date
source code. The interface for date
is also specified by POSIX.
You can even do
echo `date +%-I`
to get the hour.
Yes, although the echo
is superfluous; date +%-I
will do the same thing. The backticks are equivalent to $()
(capture the output of a command). When the shell sees that line, it does the capture and passes the output to echo
.
echo
and date
are both standalone executable, although bash has a built-in echo
command which does the same thing (the standalone echo
is there for use outside of the shell).
hostname
is an independent program too.
man strftime
, I see no facility for displaying the hostname. Have you read somewhere that this is supported?echo $(hostname)
to get it. You can even do `echo "\`$date +%-I)\`" to get the hour. I am hoping there is something similar that will work in this field by invoking a bash command like $(hostname)