- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- changing the prompt
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 10:31 AM
08-23-2002 10:31 AM
I can manipulate the PS1 with static info, like hostnames, home dirs, whatever, but I can't seem to figure out how to dynamically change PS1 with each entry of cd.
And I don't want the WHOLE pwd (god forbid!!) just the last one or two fields, maybe preceeding with '.' or something.
Any ideas would be helpful!!
- Allan
Solved! Go to Solution.
- Tags:
- PS1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 10:35 AM
08-23-2002 10:35 AM
Re: changing the prompt
Include this at the last of your profile file:
host=`hostname`
PS1='$host:$PWD># '
gl,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 10:39 AM
08-23-2002 10:39 AM
Re: changing the prompt
Thanks! That one I knew, but I only wanted the last couple of PWD args to show up. If you go down, say, 6 or 7 sub-dirs, you wind up with a big mess of a prompt.
I know you can truncate the PWD, I just don't know how it gets dynamically truncated.
- Allan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 10:39 AM
08-23-2002 10:39 AM
Re: changing the prompt
export PS1='${PWD}'
or
export PS1=`uname -n`':${PWD} # '
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 10:42 AM
08-23-2002 10:42 AM
Re: changing the prompt
This shoudl work for you. It shows the current directory you are in.
# PS1="`hostname`:`basename $PWD` "
Hai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 10:46 AM
08-23-2002 10:46 AM
Re: changing the prompt
I add a pound sign to separate the prompt from commands.
# PS1="`hostname`:`basename $PWD` # "
Hai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 10:49 AM
08-23-2002 10:49 AM
Re: changing the prompt
I prefer to have a multi-line PS1, so I can see the whole path:
systemname=`uname -n`
username=`whoami`
PS1='\[ $username - $PWD \] $systemname -> '
Which gives something like this:
[ myname - /home/myname ]
systemname -> cd /var/adm/syslog
[ myname - /var/adm/syslog ]
systemname ->
So I can see who I am currently logged in as, where I am, and what system I am on. This has saved me far too often from running a command in the wrong directory on the wrong system.
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 10:53 AM
08-23-2002 10:53 AM
Re: changing the prompt
PS1='\[ $username - $PWD \] \
$systemname -> '
At the end of the PS1 line, put a line continuation character (/) and then hit Enter to put $systemname... on the next line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 10:59 AM
08-23-2002 10:59 AM
Re: changing the prompt
Thanks for the QUICK (and I mean QUICK) responses. This is a super news group.
So far, I haven't gotten the nail on the head yet.
"basename" comes closest. I tried this myself, but for some reason `basename $PWD` returns only a static representation of the path. For example, suppose your current PWD is:
/a/b/c/d
and you do: export PS1="`basename $PWD` > " you get:
d > Which is what I was trying to do. So far, so good. But then:
cd ..
d > pwd
/a/b/c
I was hoping to see:
c > pwd
/a/b/c
I haven't gotten it yet!
- Allan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 11:08 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 11:09 AM
08-23-2002 11:09 AM
Re: changing the prompt
me=`who am i | cut -d' ' -f1`
host=`hostname`
PS1='me@$host:$PWD:# '
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 11:26 AM
08-23-2002 11:26 AM
Re: changing the prompt
You got it, right on the money! Exactly what I was looking for. I formatted your expression even prettier like this:
export PS1=`hostname`:./'${PWD##*/} > '
Which returns something like this:
myServer:./lastPath > _
And it changes with each cd command.
Cool!
One question:
I've never seen the ##*/ operator, or (or is this a grep expression?) Can you explain how this is working?
Thanks a bunch!!
- Allan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2002 12:20 PM
08-24-2002 12:20 PM
Re: changing the prompt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2002 02:04 PM
08-24-2002 02:04 PM
Re: changing the prompt
export PS1='${PWD##${PWD%/*/*}/}'
Be sure you use single quotes. This will show the current directory and one level up. It's really useful for a short prompt but with a little less ambiguity than just the basename (which bin directory is it?)
BTW: The # and % constructs are specific to POSIX shells such as ksh, bash and the HP POSIX shell. It has to do with pattern matching (shortest or longest, left or right pattern). It's a bit difficult to grasp from the man pages; try a good Korn shell book.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2002 04:00 PM
08-24-2002 04:00 PM
Re: changing the prompt
username@hostname current_working_directory root/non-root sysmbol.
for root a root user, it would look like similar to this:
root@hostname: / #
for a non-root user it would look similar to this:
user1@hostname: user1 $