Operating System - HP-UX
1833184 Members
3026 Online
110051 Solutions
New Discussion

Re: Unix prompt doesn't show up correctly on CDE

 
SOLVED
Go to solution
Shivkumar
Super Advisor

Unix prompt doesn't show up correctly on CDE

Dear Sirs/Madam,

After pasting the below command on CDE terminal of hpux it doesn't comes up correctly.

PS1=`whoami`'@'`/usr/bin/hostname`': $PWD $ '; export PS1

After pasting above command i get below output:

$ '`/usr/bin/hostname`': $PWD $ '; export PS1
>



The setting for terminal is as mentioned as shown below:-
TERM=dtterm
TERMINAL_EMULATOR=dtterm

Can someone advise how to overcome this situation ?

Thanks,
Shiv


6 REPLIES 6
Robert-Jan Goossens
Honored Contributor
Solution

Re: Unix prompt doesn't show up correctly on CDE

Hi Shiv,

edit your $HOME/.profile or put it in the /etc/profile for global system use.

PS1="`whoami`@`hostname`:"'${PWD}'""
export PS1

Hope this helps,
Robert-Jan
Bill Hassell
Honored Contributor

Re: Unix prompt doesn't show up correctly on CDE

A more modern form would be:

export PS1="$(whoami)@$(hostname):"'${PWD}'""

The grave accents have been deprecated for about 10 years in favor of $(...) and for modern POSIX shells like ksh, bash and HP's POSIX shell, you can export and assign a value on the same line.

One problem with $PWD...it can get really lengthy when cd'ing into a long directory structure. Here's a technique that shows just the current plus the parent directory, usually enough to know where you are located:

export PS1="$(whoami)@$(hostname):"'${PWD##${PWD%/*/*}/}'" # "

Now to make this permanent (ie, set when you login), you must add this to .profile in your $HOME directory. This works for 'normal' logins using telnet or ssh. But since you mentioned CDE, you are likely starting dtterm sessions with CDE and all normal Unix profiles are ignored (/etc/profile and .profile, etc). This can be very confusing but it is the way CDE was designed, probably because very few CDE users would ever use a terminal interface since it is a graphics system (big smiley face...)

But you can fix this so all terminal windows will perform a 'normal' login:

echo "*loginShell:true" >> $HOME/.Xdefaults

Now when you start dtterm windows, you'll see the same login sequence that a telnet connection will see.


Bill Hassell, sysadmin
Shivkumar
Super Advisor

Re: Unix prompt doesn't show up correctly on CDE

Bill Hassell;

I am not a system admin on this box so may not be able to edit .profile. Secondly i have been granted read only permission to .profile. Actually i have root privilege and can change it but i don't want to do it as it might violate policy of sys admin folks.

The other option was to put your script in a file in my home directory and execute it. I tried executing it but got no result.

Can you suggest a way to put in a file and execute it to get the desired output ?

Thanks,
Shiv
Bill Hassell
Honored Contributor

Re: Unix prompt doesn't show up correctly on CDE

OK. All you need to do is put the setting for PS1 into a simple file. You can copy-paste either of these lines into a file once you're logged in (and in your home directory):

export PS1="$(whoami)@$(hostname):"'${PWD}'" "

or


export PS1="$(whoami)@$(hostname):"'${PWD##${PWD%/*/*}/}'" # "

Just run vi and insert the above line into a file, perhaps called myprompt. Now because you're not permitted to change .profile, this change for your prompt won't be automatic. Each time you login, you must type:

. ./myprompt

NOTE: the above is: dot space dot slash myprompt This is called sourcing and what the first dot does is to run the command in the file. Since you have to run this file each time you login, you don't need to create the .Xdefaults file.


Bill Hassell, sysadmin
Shivkumar
Super Advisor

Re: Unix prompt doesn't show up correctly on CDE

Bill Hassell;

I just tried and it worked. Thanks a lot for your help. You seems to be a unix guru :-).

By the way what is the meaning of "sourcing" on hpux .

It seems sourcing concept is not available on other unix such as solaris and aix.

Thanks in advance,
Shiv
Bill Hassell
Honored Contributor

Re: Unix prompt doesn't show up correctly on CDE

Sourcing isn't a Unix convept, it is a shell feature, and yes, it's available on AIX, Solaris, Linux, etc since they all have shells. When you login to a Unix box, the normal mechanism is to talk to a shell program. In HP-UX, it is /usr/bin/sh which is the POSIX shell. For other Unix flavors, it might be the Bourne shell, or Korn shell (ksh) or maybe an alternative shell like bash.

Most of these shells have the Bourne shell as their ancestor but in terms of standards, ksh, bash and HP's POSIX shell are all called POSIX shells and sourcing is common to all of them including Bourne. When you run a script (a file with shell commands in it), the normal method is to start another copy of the shell program (called forking a process) and the new shell actually runs your script. But any changes to the environment such as PS1 will be lost when the script is done and the subshell terminates.

So the concept of 'sourcing' was created to have the current shell read each line and process it as if you had typed it in from the keyboard. That's why if you leave out the single dot, nothing changes in your current shell.


Bill Hassell, sysadmin