Link to home
Start Free TrialLog in
Avatar of r47463
r47463

asked on

KSH PS1 environemnt variable

From the ksh prompt I can enter the following to successfully change the prompt:

PS1="$(hostname) $ "

When I try this in a script it doesn't work and the prompt stays on "$". I've tried exporting it but that didn't seem to work either. I'm using UWIN if that's any help.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Tintin is right, buy you may want an explanation for this...

Whenever you start a shell script, a new shell is started to process the script. This means that any settings you apply in the script are only active while this new shell is alive. As soon as the script ends, the shell process exits as well, and your new PS1 variable goes with it. When you use the ". script" syntax, the contents of the script are actually read into  your current shell (it's like an include command). This way, anything you do in the script will be applied to your current shell.
in your script use full path to hostname, like
PS1="$(/path/to/hostname) $ "

If you just want to use it to make the setting permanent for your shell, then you need to source it (as described before)
Or probably your want to write it in your ~/.profile
Avatar of r47463
r47463

ASKER

Thanks for all of your help.