Operating System - HP-UX
1821297 Members
3220 Online
109632 Solutions
New Discussion юеВ

Re: Links or Aliases Question...

 
SOLVED
Go to solution
Garrin Thompson
Advisor

Links or Aliases Question...

I used to use the csh and now I've got my .profile setting me up in ksh by choice. In csh, I used to be able to type "cd" and hit enter and it would automatically cd to my home directory. Now it says "sh[2]: @: Parameter not set". Also, I used to be able to type "vipw" to vi the /etc/passwd file and now is says "lckpwdf: Permission denied
vipw: Cannot obtain lock for /etc/.pwd.lock
". I can vi /etc/passwd by typing in exactly that, but I enjoyed vipw. I'm new to Unix and still learning...your help is appreciated. :-)

Thanks,
Garrin
2 Years old on HP-UX 10.20 R9000 server
13 REPLIES 13
CHRIS_ANORUO
Honored Contributor

Re: Links or Aliases Question...

Hi Garrin,
You can use .kshrc to setup your command aliases. (Eg: alias rm=`rm -i`)

Cheers!
When We Seek To Discover The Best In Others, We Somehow Bring Out The Best In Ourselves.
Antoanetta Naghiu
Esteemed Contributor

Re: Links or Aliases Question...

Are you talking about HP-UX? If yes, you don?t need any aliases for cd and vipw to work.
Do you have set up the default shell as ksh? (see /etc/passwd file) or are you invoking the ksh shell under csh?
Is this for a regular user or for root? (vipw is a privileged command). And sh is the default for root?.

Anyway, check swlist for the following paches: PHCO_13363 sh.patch, PHCO_14084 csh patch, PHCO_16149 csh cumulative patch. (those patches are for HP-UX 11.0). I do have them installed and sh, csh, ksh are working just fine, including cd and vipw).
Garrin Thompson
Advisor

Re: Links or Aliases Question...

Chris got me on the right track for "vipw"...when I added "alias vipw='vi /etc/passwd'" to the .kshrc file, it worked. I can now type vipw and get what I expect. The "cd" command is working fine as long as I follow it with a path. I am looking for the benefit of just typing "cd" by itself and it returning me to my home directory. This is what the alias info says for "cd" in my .kshrc now: (I put 3 *'s to indicate the beginning of each new line in case it doesn't show up right).
***alias setprmt='PS1="
***[ $(/usr/bin/pwd) ]
***# "'
***setprmt
***alias cd=newcd
***function newcd
***{
*** cd "$@" >&- || return 1
*** setprmt
***}

Anyone got any clues?
2 Years old on HP-UX 10.20 R9000 server
Garrin Thompson
Advisor

Re: Links or Aliases Question...

I am running HP-UX at version B10.20.
2 Years old on HP-UX 10.20 R9000 server
Bill Hassell
Honored Contributor

Re: Links or Aliases Question...

It sounds like you are logged in as root since you are able to edit the password file. The vipw issue (Permission denied vipw: Cannot obtain lock for /etc/.pwd.lock) is caused by a previously aborted vipw. vipw always creates a lock file to prevent other root users from accidently editing the password file at the same time. Using vi directly on the password file is not recommended - use vipw - for the reason listed.

So you can remove the /etc/.pwd.lock file (after checking that there are no other copies of vipw running. Use ps -ef|grep vipw
to locate any extra copies. Once the lock file is gone, vipw will work normally.

Next is the choice of csh, then ksh for the root user. Never use csh or ksh for the root user. Neither shell will function in single user mode. Use the POSIX shell /sbin/sh which is stored in library archive mode and will work in single user mode. The POSIX shell is built with ksh as the model so it is virtually the same as ksh.

AS far as creating a dynamic PS1 prompt that shows the current directory, it is much simpler to do. Just use the shell's built in variable $PWD as in:

export PS1='$PWD #'

Note the use of single apostrophes which will cause the prompt string to be evaluated every time. If " (double quotes) were used, the current value to $PWD would be assigned to PS1 and it would not change from prompt to prompt.

However, if you cd to a really low level directory like /opt/perl5/lib/5.00503/PA-RISC2.0/auto/Opcode, then your prompt will be really long. Using a ksh/POSIX shell construct, you can limit this to just the current and one level up as in:

export PS1='${PWD##${PWD%/*/*}/} #'

What this does is to extract the rightmost directory plus the next level up. Makes it easier to see local/bin versus contrib/bin.

For a really nice prompt string, use some terminal enhancements with:

IV=$(tput bold)
EE=$(tput sgr0)
HN=$(/usr/bin/hostname)
PS1='$HN $IV${PWD##${PWD%/*/*}/}$EE # '

The PS1 string is all one line in the above listing. If the inverse video is too much, just remove $IV in the PS1 string. This will show first the hostname then the directories.


Bill Hassell, sysadmin
Garrin Thompson
Advisor

Re: Links or Aliases Question...

Wow! Thanks Bill. This is great information. It helped a lot and now "cd" works perfectly (and I do like the bold text). BUT, I do have an important question relating to the use of the POSIX shell for root. I totally believe what you've said, but I'm not sure how to invoke that shell. Right now, I am doing this in the .profile for root: START=$HOME/.kshrc Can you or anyone tell me how to just use the POSIX shell? Thanks again...everyone.
2 Years old on HP-UX 10.20 R9000 server
Denver Osborn
Honored Contributor

Re: Links or Aliases Question...

Garrin,

If you are looking to use the POSIX shell, execute # /sbin/sh, or you can modify the /etc/passwd file and replace your current shell (at the end of the line that contains your user) with /sbin/sh. Logout, login and your shell will be /sbin/sh.

hope this answeres what you were asking!
Garrin Thompson
Advisor

Re: Links or Aliases Question...

OK...I got ya, but what is the proper way to get the .profile for root to use this shell? Now I've got: START=$HOME/.kshrc So should I change it to: START=$HOME/sbin/sh ? That's what I'm wondering. I don't want to get into trouble in Single user mode if the kshell won't work and yet root's .profile is invoking it. You all are great...thanks in advance for any further help!!!
2 Years old on HP-UX 10.20 R9000 server
Garrin Thompson
Advisor

Re: Links or Aliases Question...

Just that one last question (if anyone can help) and I'll assign points for those who replied. Thanks
2 Years old on HP-UX 10.20 R9000 server
Alan Riggs
Honored Contributor
Solution

Re: Links or Aliases Question...

Garrin:
Specify /sbin/sh as teh root shell in /etc/passwd and then place your aliases and customized prompt in $HOME/.profile.

Personally, I set root's home to be /root so that it is protected against blowups of the /home filesystem.
Alan Riggs
Honored Contributor

Re: Links or Aliases Question...

Garrin:
Specify /sbin/sh as teh root shell in /etc/passwd and then place your aliases and customized prompt in $HOME/.profile.

Personally, I set root's home to be /root so that it is protected against blowups of the /home filesystem.
Garrin Thompson
Advisor

Re: Links or Aliases Question...

Thanks! I'll give that a try. You all have been very helpful.
2 Years old on HP-UX 10.20 R9000 server
Bill Hassell
Honored Contributor

Re: Links or Aliases Question...

As a followup to Garrin's question: "I am doing this in the .profile for root: START=$HOME/.kshrc Can you or anyone tell me how to just use the POSIX shell?"

The POSIX shell is a superset of ksh (not quite but the differences are mostly esoteric) so everything you did in ksk usually works in POSIX shell. The differehnce is that .profile is the default so the START= statement is not needed and you can rename your .kshrc to .profile or merge the two if you like.


Bill Hassell, sysadmin