0

I am trying to change my prompt to my hostname (Aidan) I used PS1=“\h \d \u]"

when I used it, it only changed to “localhost” does anyone know what I am doing wrong? I have the user created in the GECOS field with the full name.

6
  • Is the a typo? (Note the difference with a regular double quote character, ")
    – fra-san
    Commented Apr 2, 2021 at 15:21
  • @fra-san I meant PS1=“\h \d \u]” I tried that, and it still gives me local host for the host name
    – Jacob
    Commented Apr 2, 2021 at 15:27
  • 1
    What is the result of hostname? Commented Apr 2, 2021 at 15:28
  • 1
    What I meant is: please, edit the exact command you ran into your question, including the quotes you actually used, paying attention not to let " be replaced with or . Also, please add information such the expected and actual prompts to your question (instead of doing it in comments), since comments may be deleted and are less readable.
    – fra-san
    Commented Apr 2, 2021 at 15:35
  • 1
    Are you possibly confusing username (your user's name) and hostname (your machine's name)?
    – Kusalananda
    Commented Apr 2, 2021 at 15:35

2 Answers 2

0

If you want the user's real name from the GECOS field, I think you need to fetch it manually. I don't think there's a way to do it automatically, at least in Bash.

So,

gecos=$(getent passwd $USER | cut -d: -f5 | cut -d, -f1)
PS1='$gecos ... \$ '
0

You need to change the contents of /etc/hostname to the actual name of your host, and then reboot. You can change the name of your host for the current session using the 'hostname' command (if logged in as root), but any change you make will be lost on the next reboot if you have not also updated /etc/hostname .

1
  • 1
    It's not clear that the user wants the hostname in the prompt. They get the hostname, but the question specifically mentions the user's full name being set in the GECOS field in /etc/passwd.
    – Kusalananda
    Commented Nov 4, 2023 at 12:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .