Issue with Single Quotes and Double Quotes for prompt PS1

Hi,

Trying to change the prompt. I have the following code.

export PS1='
[$PWD]
<${USER}@`hostname -s`>$ '

The hostname is not displayed

[/users/home/abc]
<abc@`hostname -s`>$ uname -a
AIX xyz 1 6 00F736154C00

[/users/home/adcwl4h]
<adcwl4h@`hostname -s`>$

If I use double quotes, then the hostname is printed properly but the path on the screen display does not change even when I change the directory. I'm using korn shell in AIX.

So...
1) what is the diff b/w single and double quote
2) what is the correct code to display my path, user and hostname as I'm trying with the above code.

Appreciate your help.

Single quotes turn of meta meanings entirely, so I prefer them, generally. When setting PS1:

  • anything for evaluation later must be in single quotes, like $PWD or an effective id or date call.
  • Things you can set at login time, like login id, tty or host name, can be barefoot or in double quotes.
1 Like

That means

export PS1='
[$PWD]
<${USER}@'`hostname -s`'>$ '
1 Like

If user and hostname are not dynamic, why not evaluate them once?

export PS1='
[$PWD]
<'"$USER@`hostname -s`>"'$ '