0

I know that in order to modify the time display this is the menu selection:

enter image description here

and here is my current favorite:

enter image description here

BUT, when I try to add $(hostname) just like it would work in echo $(hostname),

it shows this:

enter image description here

QUESTION: How can I make it show the actual hostname?

3
  • 1
    When I look at man strftime, I see no facility for displaying the hostname. Have you read somewhere that this is supported?
    – Seamus
    Commented May 23, 2018 at 16:40
  • No, hence the question. I do know that in bash you can do 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)
    – SDsolar
    Commented May 23, 2018 at 20:40
  • Honestly, I don't know... I would guess that it's not, but I could be wrong. I say that because everything that's mentioned in the man page is from a datetime-like object. hostname is not. But, if you find a way to do that, I would love to hear of it!
    – Seamus
    Commented May 23, 2018 at 21:47

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.