Operating System - HP-UX
1834636 Members
2963 Online
110069 Solutions
New Discussion

what' differenct of ' ' and " " in PS1 enviroment variable?

 
常有慈悲心
Regular Advisor

what' differenct of ' ' and " " in PS1 enviroment variable?

PS1='$PWD '
WILL WORK
BUT PS1="$(pwd)" not work
why?
8 REPLIES 8
Naveej.K.A
Honored Contributor

Re: what' differenct of ' ' and " " in PS1 enviroment variable?

hi

single quotes keep the values as it is....
that echo $PS1 will be $PWD .i.e it doesnot expand the variable within the single quotes

but inside a double quotes it does.i.e the shell variable can be expanded from within the double quotes.

This is what happens in a POSIX shell for single and double quotes

with best wishes
Naveej
practice makes a man perfect!!!
twang
Honored Contributor

Re: what' differenct of ' ' and " " in PS1 enviroment variable?

PS1='$PWD ': PS1 is content of env variable "PWD".
To make PS1="$(pwd)" work, we can change it to PS1="`pwd`"
Naveej.K.A
Honored Contributor

Re: what' differenct of ' ' and " " in PS1 enviroment variable?

hi,

one more thing to add up
PWD is a shell variable
while pwd is a command.

regds
Naveej
practice makes a man perfect!!!
curt larson_1
Honored Contributor

Re: what' differenct of ' ' and " " in PS1 enviroment variable?

well both work for me

and using command substitution, "$(pwd)", in the PS1 prompt variable will cause poor shell performance
常有慈悲心
Regular Advisor

Re: what' differenct of ' ' and " " in PS1 enviroment variable?

i know in shell , every thing in ' ' will keep it's own property,
but why '$PWD' will prompt path ,

well "$(pwd)" only prompt old path for the
time the PS1 change ,but will not
change prompt when i change to other path?
Kiyoshi Miyake
Frequent Advisor

Re: what' differenct of ' ' and " " in PS1 enviroment variable?

Hi,

When shell sets PS1='$PWD', single quote are parsed.
So, the environment value of PS1 is $PWD, not '$PWD'.
(PS1 dosn't have single quote.)

On the other hand, when shell sets PS1="$(pwd)",
double quate are pased and execute pwd command.
So, the environment value of PS1 is /foo/bar/baz .

When shell prints a prompt, shell parses PS1.
If PS1 is $PWD, $PWD is expanded to current directory path.
But if PS1 is /foo/bar/baz ( case set PS1="$(pwd)" ),
PS1 is just /foo/bar/baz. no change.

Thanks.
常有慈悲心
Regular Advisor

Re: what' differenct of ' ' and " " in PS1 enviroment variable?

WHERE can i find some tips about PS1 ?
man sh-posix?

best regards
Thomas Bianco
Honored Contributor

Re: what' differenct of ' ' and " " in PS1 enviroment variable?

i find http://tldp.org very useful. take a look at the advanced bash scripting guide.
There have been Innumerable people who have helped me. Of course, I've managed to piss most of them off.