Pregunta

So i set the command line editor to vi in bash with this :

set -o vi

and i can see it in the set under "_=":

WEBJAVA=/production/webjava
_=vi
cvsServer=usaddat01p
ovMsgGrp=ETC_US
ovObject=PROD_US
(END)

I set it to emacs and I see it in the "_="

set -o emacs
WEBJAVA=/production/webjava
_=emacs
cvsServer=usaddat01p
ovMsgGrp=ETC_US
ovObject=PROD_US
(END)

but then i check set again and there is nothing under "_="

WEBJAVA=/production/webjava 
_=
cvsServer=usaddat01p
ovMsgGrp=ETC_US
ovObject=PROD_US
(END)

what is that "_=" symbol mean - and how do i check which command line editor I am currently cnfigured with. becuase no matter what commnand editor I set myself to, the EDITOR values is vi

EDITOR=vi

Sometimes when i log into a machine i want to see which command line editor is set - sometimes vi is set, sometimes i need to set it. I want to know how to check to see which command line editor is invoked

¿Fue útil?

Solución 2

To see which shell options are set, type:

set -o

This will show emacs on/off and vi on/off.

Otros consejos

On a related point, set -o vi and set -o emacs don't do what they may seem to do - they define the key modes of bash itself (specifically, as @mklement0 mentions, they specify the command line key bindings for interactive sessions). This has nothing to with vi and emacs themselves, it's just named after them because the corresponding key bindings are similar to the bindings that those text editors use.

If you want to switch the actual text editor, you'll need to alter the environment variable.

export EDITOR=vi

The meaning of _ is:

_

(An underscore.) At shell startup, set to the absolute pathname used to invoke the shell or shell script being executed as passed in the environment or argument list. Subsequently, expands to the last argument to the previous command, after expansion. Also set to the full pathname used to invoke each command executed and placed in the environment exported to that command. When checking mail, this parameter holds the name of the mail file.

(quoted from the reference manual). That's exactly what you're seeing here.

The _ parameter is just the final argument to the previous command.

$ : foo
$ echo $_
foo
$ : a b c d e
$ echo $_
e

For latecomers: The OP's question conflates two (mostly) unrelated concepts, which has caused confusion and resulted in answers relating to either one or the other concept:

Concept 1: Configuring the key bindings for editing the command line in an interactive bash shell.

Concept 2: Specifying the external editor program invoked by certain utilities, typically for synchronously editing a given file.

Concept 1 is most easily controlled via set -o emacs / set -o vi to allow editing the command line with emacs-like / vi-like key bindings (emacs style is the default) - note that that -like is the operative word here: neither emacs nor vi are actually involved. As the accepted answer states, examine the output of set -o to see which style is in effect, or use bind -v | egrep ' editing| keymap'. For more information about the line-editing interface, see man bash, section READLINE, and man bind.

Concept 2 is controlled by exporting the special $EDITOR variable and assigning it an external editor program that must execute synchronously, so as to block the shell until the editor process terminates (on finishing the editing task); e.g.: export EDITOR=vi

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top