tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: set -o emacs when su?



    Date:        Tue, 10 Nov 2020 18:23:25 -0500 (EST)
    From:        Mouse <mouse%Rodents-Montreal.ORG@localhost>
    Message-ID:  <202011102323.SAA27868%Stone.Rodents-Montreal.ORG@localhost>

Sorry, I've been AFK all day.

  | What do I have to do to arrange that "set -o emacs" is in effect when I
  | su?

I cannot believe I'm telling someone how to run emacs (anything emacsy).

Sigh.

  | I experimented with various things that looked like shell startup
  | files;

Did you try "man sh" and read the section "Invocation" ?
I see Michael Siegel also suggested that.

That would have told you that the "su -l" method that RVP suggested
in a reply would work - but unless you want a login shell for other
reasons, that's not the best way (that way also provides commands
that will be executed when you (or anyone) login as root).

It would also tell you (in a -8 or earlier man page):

     If the environment variable ENV is set on entry to a shell, or is
     set in the .profile of a login shell, and either the shell is
     interactive, or the posix option is not set, the shell next reads
     commands from the file named in ENV.

Since su starts an interactive shell (usually anyway) the bit about the
posix option is irrelevant (that is, POSIX only expects the file named
by ENV to be read in interactive shells, so if the shell is running in
POSIX compat mode, and isn't interactive, ENV isn't used .. this part
wouldn't be in the man page for shells before -8, they simply always
read the ENV file).

If the file named doesn't exist, it is silently ignored.

In a -9 man page (or later) it says instead of the final clause of the
previous quote:

     the shell then performs parameter and arithmetic expansion on
     the value of ENV, (these are described later) and if no errors occurred,
     then reads commands from the file name that results.

So you can set ENV (in -9 or later) something like

	ENV=${HOME}/.shrc-'${EUSER}'

and then have ~/.shrc-root file to run whatever commands you want.
Of course, if you always want some commands run whenever you start
an interactive shell, you can just use $HOME/.shrc (or whatever).

If you only need those run in interactive shells, wrap the whole
file like:

	case "$-" in
	*i*)	# the commands go here, "set -o vi" would be a good choice!
		;;
	esac

If you only want the file read once, when you su, then have it
either unset, or alter, ENV.

The file can start #! /bin/sh if you want, but in this context,
that's just a comment to be ignored -- it is read in the exact same
way as the '.' command reads files, so an alternative wrapper
to skip processing by non-interactive shells is

	case "$-" in
	*i*)	;;
	*)	return;;
	esac

at the head of the file ('.' files are kind of like functions, and
can be returned from).

  | Did I do something wrong in the install or what?  Surely it's not
  | *supposed* to be this difficult.

The problem is all those missing catpages, obviously :-)

kre



Home | Main Index | Thread Index | Old Index