为什么我的箭头键在 sh 中不起作用?

Joe*_*Joe 20 dash

我最近安装了 Ubuntu,当我在终端上运行 sh 时,我的箭头键不起作用,所以我无法查看通话记录或编辑我正在输入的任何内容。它只是作为像^[[A .

登录外壳是bash并且它工作正常,但是一旦我切换到sh,它们就不起作用。

我怎样才能解决这个问题?

Arc*_*ege 17

/bin/sh(短划线)壳是一POSIX兼容,缩减功能壳更有效(更小的),用于引导系统。作为其中的一部分,不包括历史记录和高级命令行编辑。它更适合严格的 POSIX 脚本而不是交互式 shell。这个想法是默认情况下“登录”shell 将是 bash,但引导系统将使用 dash。Ubuntu 11.04 中的手册页显示 dash 具有历史记录和命令行编辑功能,但该程序没有这些功能。查看基本可执行文件的大小。

$ ls -l /bin/*ash /bin/sh
-rwxr-xr-x 1 root root 822420 Mar 31 15:26 /bin/bash
-rwxr-xr-x 1 root root  83848 Nov 15  2010 /bin/dash
lrwxrwxrwx 1 root root      4 May 17 21:15 /bin/rbash -> bash
lrwxrwxrwx 1 root root      4 May 17 21:15 /bin/sh -> dash
$ strings /bin/bash | egrep -ci 'fc|hist'
181
$ strings /bin/dash | egrep -ci 'fs|hist'
1
Run Code Online (Sandbox Code Playgroud)

尝试习惯运行$SHELLbash而不只是sh.


小智 10

如果/bin/shDash,则必须--with-libedit在编译前对其进行配置。否则你仍然可以set -o vi在 shell 中运行,但它不会做任何有用的事情。


Ted*_*ddy 0

sh没有任何历史。至少,我的没有:

server$ sh
\h$ history 
sh: history: not found
\h$ fc
sh: fc: not found
\h$ exit
server$ type sh
sh is hashed (/bin/sh)
server$ ll /bin/sh
lrwxrwxrwx 1 root root 4 Jun  1 18:43 /bin/sh -> dash*
Run Code Online (Sandbox Code Playgroud)

  • @mikeserv,不确定你的意思,但重申一下,所有 `fc`、`$FCEDIT`、`$HISTFILE`、`$PS1` 在 POSIX 中都是可选的(标有 UP 表示“用户可移植性”)。Unix 一致系统的 `sh` 将具有这些,因为 UP 是 Unix 一致性所必需的(除其他外,Unix 还要求 `echo -e` 输出 `-e<LF>`)。但如果系统/shell 仅声明符合 POSIX,那么它就不需要实现这些。对于 Debian `ash`,它可以在编译时使用 --with-libedit 启用,如前所述,但 Debian 至少没有。 (2认同)