Shell How to change EDITOR to default parameter

As A root I forced to use sh shell and evry time export the EDITOR variable. I've read that I should edit the .profile file in orderd to override the default EDITOR variable, I wonder where I can actully set it as originally it was set somewhere.

here is my .profile, but it doesn't work at all:

Code:
# $FreeBSD$
#
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:~/bin
export PATH
HOME=/root
export HOME
EDITOR="/usr/local/bin/nano"
export EDITOR
TERM=${TERM:-xterm}
export TERM
PAGER=less
export PAGER

# set ENV to a file invoked each time sh is started for interactive use.
ENV=$HOME/.shrc; export ENV

# Query terminal size; useful for serial lines.
if [ -x /usr/bin/resizewin ] ; then /usr/bin/resizewin -z ; fi

# Uncomment to display a random cookie on each login.
# if [ -x /usr/bin/fortune ] ; then /usr/bin/fortune -s ; fi
 
Code:
 A login shell first reads
     commands from the files /etc/profile and then .profile in a user's home
     directory, if they exist.  If the environment variable ENV is set on
     entry to a shell, or is set in the .profile of a login shell, the shell
     then subjects its value to parameter expansion and arithmetic expansion
     and reads commands from the named file.  Therefore, a user should place
     commands that are to be executed only at login time in the .profile file,
     and commands that are executed for every shell inside the ENV file.  The
     user can set the ENV variable to some file by placing the following line
     in the file .profile in the home directory, substituting for .shrc the
     filename desired:

           ENV=$HOME/.shrc; export ENV

     The first non-option argument specified on the command line will be
     treated as the name of a file from which to read commands (a shell
     script), and the remaining arguments are set as the positional parameters
     of the shell ($1, $2, etc.).  Otherwise, the shell reads commands from
     its standard input.
See sh(1)
 
Code:
 A login shell first reads
     commands from the files /etc/profile and then .profile in a user's home
     directory, if they exist.  If the environment variable ENV is set on
     entry to a shell, or is set in the .profile of a login shell, the shell
     then subjects its value to parameter expansion and arithmetic expansion
     and reads commands from the named file.  Therefore, a user should place
     commands that are to be executed only at login time in the .profile file,
     and commands that are executed for every shell inside the ENV file.  The
     user can set the ENV variable to some file by placing the following line
     in the file .profile in the home directory, substituting for .shrc the
     filename desired:

           ENV=$HOME/.shrc; export ENV

     The first non-option argument specified on the command line will be
     treated as the name of a file from which to read commands (a shell
     script), and the remaining arguments are set as the positional parameters
     of the shell ($1, $2, etc.).  Otherwise, the shell reads commands from
     its standard input.
See sh(1)
The EDITOR=vi was in .profile.
 
Code:
 A login shell first reads
     commands from the files /etc/profile and then .profile in a user's home
     directory, if they exist.  If the environment variable ENV is set on
     entry to a shell, or is set in the .profile of a login shell, the shell
     then subjects its value to parameter expansion and arithmetic expansion
     and reads commands from the named file.  Therefore, a user should place
     commands that are to be executed only at login time in the .profile file,
     and commands that are executed for every shell inside the ENV file.  The
     user can set the ENV variable to some file by placing the following line
     in the file .profile in the home directory, substituting for .shrc the
     filename desired:

           ENV=$HOME/.shrc; export ENV

     The first non-option argument specified on the command line will be
     treated as the name of a file from which to read commands (a shell
     script), and the remaining arguments are set as the positional parameters
     of the shell ($1, $2, etc.).  Otherwise, the shell reads commands from
     its standard input.
See sh(1)
But, I'm still wondering why I can't see the value of the EDITOR by typing echo $EDITOR in sh terminal. Is it iside some othe variable?
 
What is the actual shell you're using? echo $SHELL and/or getent passwd root.
 
It shouldn't matter but you know you can put this on one line right?
Code:
EDITOR="/usr/local/bin/nano"
export EDITOR
Better:
Code:
export EDITOR="/usr/local/bin/nano"
 
Code:
# cat .shrc
# $FreeBSD$
#
# .shrc - bourne shell startup file
#
# This file will be used if the shell is invoked for interactive use and
# the environment variable ENV is set to this file.
#
# see also sh(1), environ(7).
#


# file permissions: rwxr-xr-x
#
# umask 022

# Uncomment this to enable the builtin vi(1) command line editor in sh(1),
# e.g. ESC to go into visual mode.
# set -o vi


# # some useful aliases
# alias h='fc -l'
# alias j=jobs
# alias m="$PAGER"
# alias ll='ls -laFo'
# alias l='ls -l'
# alias g='egrep -i'

# # be paranoid
# alias cp='cp -ip'
# alias mv='mv -i'
# alias rm='rm -i'

# read(2) of directories may not be desirable by default, as this will provoke
# EISDIR errors from each directory encountered.
# alias grep='grep -d skip'

# set prompt: ``username@hostname:directory $ ''
PS1="\u@\h:\w \\$ "

# search path for cd(1)
# CDPATH=:$HOME
EDITOR='nano'
 
I'm not sure what is going on.

Could you do the following:
Log out, log in, and then type the following commands:
ps -p $$
cat ~/.profile | grep EDITOR
export -p | grep EDITOR
echo $EDITOR

and show every command and its output.
 
I'm not sure what is going on.

Could you do the following:
Log out, log in, and then type the following commands:
ps -p $$
cat ~/.profile | grep EDITOR
export -p | grep EDITOR
echo $EDITOR

and show every command and its output.
Code:
# ps -p $$
  PID TT  STAT    TIME COMMAND
16621  1  S    0:00,00 su (sh)
# cat ~/.profile | grep EDITOR
EDITOR=/usr/local/bin/nano
export EDITOR
# export -p | grep EDITOR
# echo $EDITOR

crontab -e is still vi :'‑(
 
The EDITOR variable is not set correctly, I do not know why.

At the command line, type the following commands:
export EDITOR=/usr/local/bin/nano
echo $EDITOR
What is the output for each?

What do you get now with the command:
crontab -e
 
Please enter the following commands and post the results:
echo $PATH
pwd
id
getent passwd root
echo $USER
echo $PAGER
echo $PS1
which nano
 
The EDITOR variable is not set correctly, I do not know why.

At the command line, type the following commands:
export EDITOR=/usr/local/bin/nano
echo $EDITOR
What is the output for each?

What do you get now with the command:
crontab -e
# export EDITOR=/usr/local/bin/nano
# echo $EDITOR
/usr/local/bin/nano

crontab -e
it is nano
but after relogin this is vi again.
 
Please enter the following commands and post the results:
echo $PATH
pwd
id
getent passwd root
echo $USER
echo $PAGER
echo $PS1
which nano
# echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/ihor/bin
# pwd
/usr/home/ihor
# id
uid=0(root) gid=0(wheel) groups=0(wheel),5(operator)
# getent passwd root
root:..Charlie &:/root:/bin/sh
# echo $USER
root
# echo $PAGER

# echo $PS1
#
# which nano
/usr/local/bin/nano
#
 
Something appears to be weird about the way you changed the root shell. When you log in as "root" your home directory should be /root but it shows up in your $PATH and in your pwd as /home/ihor (or as /usr/home/ihor, which is effectively the same directory, because /home is a link to /usr/home). Yet, id and $USER both show that you are logged in as "root".

Next, presumably in /home/ihor/.profile you reset the HOME environment variable to /root. Therefore, you then probably executed /root/.shrc (instead of /home/ihor/.shrc), because in your .profile file, the statement ENV=$HOME/.shrc; export ENV will expand to ENV=/root/.shrc instead of to ENV=/home/ihor/.shrc.

It appears that you have made some of your changes manually instead of by using the chsh command, which is the recommended way of changing the root shell.

At this point you should proceed very cautiously before making any more changes. Have you manually edited your /etc/passwd file?
 
Back
Top