1830938 Members
1758 Online
110017 Solutions
New Discussion

shell queries

 
SOLVED
Go to solution
Omar Alvi_1
Super Advisor

shell queries

Hi,

The default shell for root is /sbin/sh and not /usr/bin/sh. Why? (maybe for sigle user mode?) Does it still have all POSIX functionality.

I read that vi is on by default for POSIX (/usr/bin/sh), but I have to turn it on manually set -o vi.

Why doesn't my env variable $SHELL's value change when I change my shell?

As for recalling history, is it that the POSIX shell requires the HISTFILE variable to be defined whereas the Korn shell (/usr/bin/ksh) does not.

From where does the vi read history command if I have removed the .sh_history file?

Simple questions, but put together they're somewhat confusing

Regards,

-Alvi
7 REPLIES 7
Tim Adamson_1
Honored Contributor

Re: shell queries

Hi,

If the shell lived in root, then you would not be able to boot single user or maintenance level.

The posix shell does require the HISTFILE environment variable to be defined.


Hope it helps
Yesterday is history, tomorrow is a mystery, today is a gift. That's why it's called the present.
Robert-Jan Goossens
Honored Contributor

Re: shell queries

Hi,

1 Yes it is for single user mode / maintenance mode /usr is not mounted in single user mode, therefore your system will not boot if you use /usr/bin/sh as a shell for root.

2 .profile variable for SHELL /sbin/sh

EDITOR=vi
export EDITOR

3 .profile variables

HISTFILE=/root/.sh_history
PS1="$(hostname):\$PWD\# "
HISTSIZE=250
export HISTFILE PS1 HISTSIZE

4 .sh_history will be recreated at next login.

Hope it helps,

Robert-Jan.
Massimo Bianchi
Honored Contributor
Solution

Re: shell queries

Hi,
in addition to previous execllent respinse, i add this:

export HISTFILE=$HOME/.sh_history`tty|tr / _`


With this setting of history file, expecially usefull for root, each separate root connection will have his own history file, with many important consequences:

- every other root can check what the other is doing separately,
- you get no "rm -r *" by accident, recalling hte command of someone else
- when you login interactively, with "who -HRT" you can check what the others are doing

Massimo
john korterman
Honored Contributor

Re: shell queries

Hi Omar,
The SHELL variable only shows the login shell, i.e. the original shell, therefore it does not change.

regards,
John K.

it would be nice if you always got a second chance
Omar Alvi_1
Super Advisor

Re: shell queries

Thanks for the very useful advice Massimo.

I don't know why, but on one of my systems I'm not able to set history for the default /sbin/sh shell. I have the variables defined, and DTSOURCEPROFILE=true uncommented, but no success. HISTFILE defined and created.

Another thing ... Is there no HOSTNAME built in shell variable?

And does the Korn shell not require the HISTFILE variable defined, or the history file itself. I noted history working in ksh despite deleting the .sh_history.
Massimo Bianchi
Honored Contributor

Re: shell queries

>I don't know why, but on one of my systems I'm >not able to set history for the default /sbin/sh >shell. I have the variables defined, and >DTSOURCEPROFILE=true uncommented, but no >success. HISTFILE defined and created.

Can you try to telnet to the server anc check? Maybe is related to DCE and not to the settings



>Another thing ... Is there no HOSTNAME built in >shell variable?

No,
but you can define your own in .profile

HOSTNAME=$(hostname)

>And does the Korn shell not require the >HISTFILE variable defined, or the history file >itself. I noted history working in ksh despite >deleting the .sh_history.

If you were using ksh and after deleted the .sh_history, at next logon history won't work.
AFAIK it uses the file, bua file can be deleted even if it is open by another process (thanks unix!).

Test this:

vi pippo.txt


edit it, leaving it open

from another shell, delete pippo.txt.

You will be able to edit it the same :)

Massimo
Omar Alvi_1
Super Advisor

Re: shell queries

Found out why the history wasn't working.

In the .profile I was using an undefined variable causing an error. Nothing following that line was executed.

Once I corrected the error History works fine. Is this also default behaviour, shouldn't the shell continue parsing .profile despite the error?

... and thanks again Massimo for giving insight w.r.t working.

Regards,

-Alvi