TL;DR : default shell man page says there's vi editing mode, but set -o vi
doesn't actually enable it
In many shells, including dash
the POSIX standard dictates that set -o vi
will enable vi editing mode, in which user of interactive shell can navigate line using vi-style of shortcuts. In dash
( Ubuntu's default shell symlinked to /bin/sh
) this doesn't work, even though man page specifies that this feature is available.
Example :
$ dash
$ set -o vi
$ hello wolrd^[I
What was supposed to happen there is that with Esc , Shift + i shortcut the cursor should have jumped to the beginning of the line. As you can see, I get a control character as output instead. I've asked a few users to test this in AskUbuntu Chat, and they confirmed the same behavior.
Note, that this is not related to terminal emulator - I tested it in 3 different ones: xterm, gnome-terminal, and terminator. I've tested this with other shells, bash
, mksh
and ksh93
- all work properly as expected, so this is dash
-only issue.
I was curious about this so I downloaded a source code tarball from the upstream DASH downloads and extracted the source files. I checked for a README file which should provide information on the program and its build options, but there wasn’t any, so I ran
./configure --help
and its output includes:So, it looks like the libedit library is used to provide line editing capabilities but this is not the default when building the source. I also found this response to a mailing list message on set -o vi not working:
I checked what libraries were linked to the
dash
executable on my Ubuntu server and notedlibedit
wasn’t included:I imagine that when the Debian package maintainers are building the
dash
package, they omit this optional configuration as they would not wantsh
to have external dependencies on other libraries. They could probably link the library statically but the main reason for usingdash
assh
is to keep the shell as small and fast as possible so that the start-up scripts run quickly.Edit: I just searched for “libedit dash” and the top result was a very similar question on this site which was well answered by muru.
Building Dash with line editing support
For those who might be interested, these are are steps required to build from source.
Download the most recent source tarball:
Verify the authenticity of the tarball:
Extract the source files and change into the source directory:
Run
./configure --with-libedit
to create the Make files. However, this will fail quietly unless the development version of thelibedit
library is installed. It would be better if the configure script complained more verbosely as it wasn’t obvious that it was failing to find the required files.Build the program and (optionally) install it into
/usr/local/bin
: