1834903 Members
2519 Online
110071 Solutions
New Discussion

.profile POSIX shell

 
SOLVED
Go to solution
Jason Heisley
Occasional Advisor

.profile POSIX shell

I am trying to get the hostname to appear at the prompt.

In .profile
export PS1='$LOGNAME@$hostname: $PWD $'

All I get is a blank space. Is the hostname not loaded at startup?
12 REPLIES 12
H.Merijn Brand (procura
Honored Contributor

Re: .profile POSIX shell

it's either

export PS1='$LOGNAME@`hostname`: $PWD $'

which uses the command 'hostname' in backticks, or

export PS1='$LOGNAME@$HOST: $PWD $'

using the environment variable $HOST, which is not always set, so I'd go for the backtick way
Enjoy, Have FUN! H.Merijn
James Beamish-White
Trusted Contributor
Solution

Re: .profile POSIX shell

I use command execution....

PS1='('`hostname`' $LOGNAME) $PWD $ '

Try that.

Cheers,
James
GARDENOFEDEN> create light
Charles McCary
Valued Contributor

Re: .profile POSIX shell

Here's one:

PS1=`uname -n`:`id -un`:'${PWD}''# '\
Helen French
Honored Contributor

Re: .profile POSIX shell

Hi,

If you just want the hostname at the prompt, add this to the .profile:

PS1="`hostname`# "

HTH,
Shiju
Life is a promise, fulfill it!
Ceesjan van Hattum
Esteemed Contributor

Re: .profile POSIX shell

Your $hostname (or $HOSTNAME) is not set in your .profile while entering your shell.

You can also do a:
export PS1="$LOGNAME@`hostname`:$PWD $"
(using dubble-quotes and back-quotes); this works just fine too.

Regards,
Ceesjan
A. Clay Stephenson
Acclaimed Contributor

Re: .profile POSIX shell

Replace export PS1='$LOGNAME@$hostname: $PWD $'

with
export PS1=$LOGNAME@`hostname`':$PWD: '

If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: .profile POSIX shell

Hi Jason:

# export PS1="$LOGNAME@$(hostname): $PWD $"

Regards!

...JRF...
H.Merijn Brand (procura
Honored Contributor

Re: .profile POSIX shell

Looks like an easy one: 7 answers in one minute!

I beat you, being the first :)))

N/A
Enjoy, Have FUN! H.Merijn
Jason Heisley
Occasional Advisor

Re: .profile POSIX shell

I used James Beamish-White
post it works great.
procura post only returns hostname not the actual host name. Sorry

As for the others I have not tried them.
Roger Baptiste
Honored Contributor

Re: .profile POSIX shell

hi,

this is the prompt i use. in the .profile file:
**
PWD=`pwd`
HOST=`hostname`
PS1='$HOST@$PWD>'
export PWD HOST PS1
**

HTh
raj
Take it easy.
H.Merijn Brand (procura
Honored Contributor

Re: .profile POSIX shell

That's because it's between single quotes :( and single quotes do not interpolate backticks

export PS1='$LOGNAME@'`hostname`': $PWD $'

should be it

I should have known it would be toooo easy :0

The comments however still hold
Enjoy, Have FUN! H.Merijn
Holger Knoppik
Valued Contributor

Re: .profile POSIX shell

Hi Jason,

and another combination:
export PS1="$LOGNAME@`hostname`:\$PWD\$ "

RGDS, Holger
Live long and prosper!