Operating System - HP-UX
1828045 Members
1833 Online
109973 Solutions
New Discussion

Re: Equivalent bash shell prompt (linux) in POSIX shell prompt (HP-UX)

 
SOLVED
Go to solution
yc_2
Regular Advisor

Equivalent bash shell prompt (linux) in POSIX shell prompt (HP-UX)

Hi,

In linux, I can set the shell prompt as follows:
:
PS1=[\u@\h \W]\$
:

Is there an equivalent for \W in HP-UX POSIX shell ?

Where \W is an escape sequence of the basename of the current working directory.



Rgds,
YC
11 REPLIES 11
RikTytgat
Honored Contributor

Re: Equivalent bash shell prompt (linux) in POSIX shell prompt (HP-UX)

Hi,

I did not try this with a sh-posix shell, but with a Linux Korn shell (na \\W available either).

Try:

export PS1='[${PWD}]\\$ '

So, use single quotes!

This should put the current working directory in the prompt.

Hope this helps,
Rik
RikTytgat
Honored Contributor

Re: Equivalent bash shell prompt (linux) in POSIX shell prompt (HP-UX)

Hi again,

In the previous version of the forums, a backslash had to be escaped.

That's why you see 2 backslashes in my previous post. It should be just one backslash, of course.


Bye,
Rik.
Clemens van Everdingen
Honored Contributor

Re: Equivalent bash shell prompt (linux) in POSIX shell prompt (HP-UX)

Hi,

This should do the trick !

export PS1="[ $PWD ] "

Good luck !

CvE
The computer is a great invention, there are as many mistakes as ever, but they are nobody's fault !
yc_2
Regular Advisor

Re: Equivalent bash shell prompt (linux) in POSIX shell prompt (HP-UX)

Hi,

I don't need a full path directory, I only need the last directory of the full path. This can be done in Linux Bash shell with \W.


Rgds,
YC
Clemens van Everdingen
Honored Contributor

Re: Equivalent bash shell prompt (linux) in POSIX shell prompt (HP-UX)

Hi,

Ok this is the thing for the last dir !

export PS1=${PWD##*/}

CvE
The computer is a great invention, there are as many mistakes as ever, but they are nobody's fault !
RikTytgat
Honored Contributor

Re: Equivalent bash shell prompt (linux) in POSIX shell prompt (HP-UX)

Hi,

Try this one:

export PS1='[$(basename ${PWD})]\$ '

Mind that the single quotes are required. In the case of double quotes, the value is fix and will not change after a directory change.

Bye,
Rik
Clemens van Everdingen
Honored Contributor
Solution

Re: Equivalent bash shell prompt (linux) in POSIX shell prompt (HP-UX)

Hi,

all together there are a lot of options, but I think this is the final one you meant to achieve.

export PS1='[(${PWD##*/})]\$ '

This one will only display the last directory you are in and is changing again when you cd to an other directory.

CvE
The computer is a great invention, there are as many mistakes as ever, but they are nobody's fault !
yc_2
Regular Advisor

Re: Equivalent bash shell prompt (linux) in POSIX shell prompt (HP-UX)

Hi Clemens,

Would you like to share where can I learn these tricks ?


Thanks,
Yc
Bruce Regittko_1
Esteemed Contributor

Re: Equivalent bash shell prompt (linux) in POSIX shell prompt (HP-UX)

Hi,

Any decent shell programming book -- Korn, Bourne, or POSIX -- will have these "tricks". Another great place to learn shell programming is in HP's POSIX Shell Programming class. Five days of shell tips, tricks, and programs.

--Bruce
www.stratech.com/training
Felix J. Liu
Advisor

Re: Equivalent bash shell prompt (linux) in POSIX shell prompt (HP-UX)

Here is what I have:

export VISUAL=emacs

MACHINENAME=`uname -n | cut -d. -f1`
export PS1='$MACHINENAME:$PWD> '

The first line is to use command line editing by pressing ctrl-p and ctrl-n for previous and next command typed. Cursor movement is down by ctrl-f and ctrl-b. I like this one over seting it to vi.

The last 2 lines give you a prompt like

castor:/home/felix>

The path on the prompt will get longer and longer as you go deep into subdirectories.

P.S. There is a ksh in linux distribution, named pdksh.
Chris Campbell_1
Occasional Advisor

Re: Equivalent bash shell prompt (linux) in POSIX shell prompt (HP-UX)

You might want to install the bash shell on your HP-UX system. It's usually the first thing I install on an HP box after HP-UX. You can find a software distributor (SD-UX) package at:
http://hpux.cs.utah.edu
or you can download and compile it if you like from a number of places.

--Chris