1836512 Members
2111 Online
110101 Solutions
New Discussion

Re: PWD in PS1

 
SOLVED
Go to solution
Bill McNAMARA_1
Honored Contributor

PWD in PS1

hi

this one would get a quicker response than by rooting through docs etc..

I want PS1 to go
user:hostname:/directory/path >

what's the entry I should use for the export PS1=
in my .profile

Thanks,
Bill
It works for me (tm)
20 REPLIES 20
Frederic Sevestre
Honored Contributor

Re: PWD in PS1

Hi,

You can try : PS1=`whoami`:`hostname`':$PWD>'
It works fine.

Fr??d??ric
Crime doesn't pay...does that mean that my job is a crime ?
James Beamish-White
Trusted Contributor

Re: PWD in PS1

Hi Bill,

user:hostname:/directory/path >

PS1='$LOGNAME:'`hostname`':$PWD > '

Cheers,
James
GARDENOFEDEN> create light
Darrell Allen
Honored Contributor

Re: PWD in PS1

Hi Bill,

PS1=`whoami`":"`hostname`":"'$PWD >'

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Marcin Wicinski
Trusted Contributor

Re: PWD in PS1

Hi Bill,

PS1=`tput smso`$(whoami)":"$(hostname)'${PWD#$HOME/}# '">"

Later,
Marcin Wicinski
Marcin Wicinski
Trusted Contributor

Re: PWD in PS1

Sorry, one mistake:

PS1=`tput smso`$(whoami)":"$(hostname)'${PWD#$HOME/}# '">"`tput rmso`
Marcin Wicinski
Bill McNAMARA_1
Honored Contributor

Re: PWD in PS1

sorry, forgot to mention.

I need this to echo the export

ie:

echo 'export PS1='$LOGNAME:'`hostname`':$PWD > ' '

or equivalent
It works for me (tm)
James Beamish-White
Trusted Contributor

Re: PWD in PS1

Hi Bill

echo? Why? You should be able to do:

PS1=...
export PS1

If you need to echo it... you should be able to escape any special characters above with a \ and the echo should work.

Cheers,
James
GARDENOFEDEN> create light
Bill McNAMARA_1
Honored Contributor

Re: PWD in PS1

it has to echo because it goes into an ignite post_install_script.

Later,
Bill
It works for me (tm)
Sanjay_6
Honored Contributor

Re: PWD in PS1

Hi Bill,

Use this in your .profile

HOST=`/usr/bin/hostname`
USER=$LOGNAME
export PS1='$USER:$HOST:$PWD>'

Hope this helps.

Regds
Frederic Sevestre
Honored Contributor

Re: PWD in PS1

Hi,
With echo :
echo "PS1=\`whoami\`:\`hostname\`:'\$PWD > '"
Regards
Fr??d??ric
Crime doesn't pay...does that mean that my job is a crime ?
Bill McNAMARA_1
Honored Contributor

Re: PWD in PS1

user must change to who I su to.

and su without the - so via whoami.

But it must be dome via an echo so all the ''s won't work.

Later,
Bill
It works for me (tm)
Frederic Sevestre
Honored Contributor

Re: PWD in PS1

Oups, i forget the export :
echo "export PS1=\`whoami\`:\`hostname\`:'\$PWD > '"

Crime doesn't pay...does that mean that my job is a crime ?
Bill McNAMARA_1
Honored Contributor

Re: PWD in PS1

root:pereal:/usr > echo "export PS1=\`whoami\`:\`hostname\`:'\$PWD > '"
export PS1=`whoami`:`hostname`:'$PWD > '
root:pereal:/usr > export PS1=`whoami`:`hostname`:'$PWD > '
root:pereal:/usr > id
uid=0(root) gid=3(sys)
root:pereal:/usr > su www
root:pereal:/usr > id
uid=30(www) gid=1(other)
root:pereal:/usr >

Not quite....
Later,
Bill
It works for me (tm)
G. Vrijhoeven
Honored Contributor
Solution

Re: PWD in PS1

Hi Bill,

You can add:
`id | awk -F"\(" '{print}'|awk -F"\)" '{print $1}'`

for username changes

Hope this will help,

Gideon
Volker Borowski
Honored Contributor

Re: PWD in PS1

What about this ?

# id
uid=0(root) gid=3(sys) groups=0(root),1(other),2(bin),4(adm),5(daemon),6(mail),7(lp),20(users)
# id -u -n
root
# su e30adm
% id -u -n
e30adm
%

Volker
G. Vrijhoeven
Honored Contributor

Re: PWD in PS1

Sorrie forgot something:

id | awk -F"\(" '{print $2}'|awk -F"\)" '{print $1}'
Darrell Allen
Honored Contributor

Re: PWD in PS1

Hey Bill,

su www doesn't execute .profile so you're going to have to reset PS1, right? Your environment didn't change, just your id.

I'm still not following on the need for echo.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Volker Borowski
Honored Contributor

Re: PWD in PS1

Hi Bill,

thanks for the ten, but does it actually work now ???

I think I now understand what you want, and it will not work with my solution either, because either
`whoami` and `id -u -n`
are evaluated at the time PS1= is set, while $PWD is an embeded shell-variable and updated dynamicly. Same with the hostname.

So I suspect after

root:pereal:/usr > su www

you want the prompt to appear as

www:pereal:/usr >

???
Right / Wrong / Confusion
Volker
Bill Hassell
Honored Contributor

Re: PWD in PS1

If you cd real deep into the Ignite directory, you might end up with a prompt string that is REALLLLY long:

bambam:/opt/ignite/newconfig/var/opt/ignite/local/manifest #

Here's a nice shell construct that will capture the last 2 directories in the tree:

HN=$(/usr/bin/hostname)
PS1='$HN :${PWD##${PWD%/*/*}/} # '

Now the prompt is:

bambam:local/manifest #

If you want just the current basename directory, trim the above down to:

PS1='$HN :${PWD##*/} # '


Bill Hassell, sysadmin
Darrell Allen
Honored Contributor

Re: PWD in PS1

Okay, for really long dir paths in the prompt use:
PS1=`whoami`":"`hostname`":"'$PWD
> '

Note the newline after $PWD continues the prompt on the next line.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)