Delete key doesn’t work on command line

keyboard shortcutsksh

**Note: I asked this same question on SuperUser, but didn't get any response. I now realize this is a more appropriate forum for this particular question.*

In a ksh shell, the Delete key doesn't work appropriately on the command line. I get a ~ when I press Delete.

How do I:

  1. bind the functionality of "Delete the character at the cursor"
    to the Delete keyboard button? (Control-D behaves like I expect the
    delete button to work and my attempts at using an alias were
    unsuccessful and likely naive.)
  2. bind the functionality of "Move to the first of the line" to the Home keyboard button? (Control A does this now, but I want Home to do it.)
  3. bind the functionality of "Move to the end of the line" to the End keyboard button? (Control E does this now, but I want end to do it.)

Final(?) Update

I stumbled across something that works, but I don't understand quite why. This works:

bind '^[[3'=prefix-2
bind '^[[3~'=delete-char-forward

According to http://www.qnx.com/developers/docs/6.3.2/neutrino/utilities/k/ksh.html#bind,

prefix-2
Key binding: ^X, ^[[
Introduces a 2-character command sequence.

So my updated question is why do I need to use prefix-2 for this? Please translate for me so I can understand so I don't have to bug everyone again about this.

OLD STUFF FOLLOWS

UPDATE

It turns out that ESC in QNX is ^[. Using the command bind '^[[3~'='delete-char-backward' I am able to get the cursor to overwrite the character under the cursor with a ~. This is some progress at least–I now know how to spell Delete Key for the shell. Most things I have seen on the web say that the delete key is ^?, but that doesn't seem to work for me. Also, I should mention I am accessing this via PuTTy.

I don't understand because Control D does what I want the delete key to do. I tried binding it to eot-or-delete again to no avail.

This should be simple, right?

UPDATE 2:

 bind | grep prefix
^X = prefix-2
^[ = prefix-1
ÿ = prefix-3
^[O = prefix-2
^[[ = prefix-2


bind | grep '[^ -~]'
ÿ = prefix-3
à  = beginning-of-line
à¡ = up-history
ठ= backward-char
ঠ= forward-char
ਠ= end-of-line
à© = down-history
ଠ= delete-char-forward
à´ = backward-word
ච= forward-word

UPDATE 3: More of my settings

ENV setting

 echo $ENV
/etc/kshrc

BIND Complete Output

bind
^A = beginning-of-line
^B = backward-char
^C = abort
^D = eot-or-delete
^E = end-of-line
^F = forward-char
^G = abort
^H = delete-char-backward
^I = complete
^J = newline
^K = kill-to-eol
^L = redraw
^M = newline
^N = down-history
^O = newline-and-next
^P = up-history
^R = search-history
^T = transpose-chars
^U = kill-line
^V = version
^W = kill-region
^X = prefix-2
^Y = yank
^[ = prefix-1
^\ = no-op
^] = search-character-forward
^^ = quote
^_ = eot
^? = delete-char-backward
ÿ = prefix-3
^[^H = delete-word-backward
^[^X = complete-file
^[^[ = complete
^[^] = search-character-backward
^[  = set-mark-command
^[# = comment
^[* = expand-file
^[. = prev-hist-word
^[0 = set-arg
^[1 = set-arg
^[2 = set-arg
^[3 = set-arg
^[4 = set-arg
^[5 = set-arg
^[6 = set-arg
^[7 = set-arg
^[8 = set-arg
^[9 = set-arg
^[< = beginning-of-history
^[= = complete-list
^[> = end-of-history
^[? = list
^[C = capitalize-word
^[L = downcase-word
^[O = prefix-2
^[U = upcase-word
^[[ = prefix-2
^[_ = prev-hist-word
^[b = backward-word
^[c = capitalize-word
^[d = delete-word-forward
^[f = forward-word
^[g = goto-history
^[h = delete-word-backward
^[l = downcase-word
^[u = upcase-word
^[y = yank-pop
^[^? = delete-word-backward
^X^X = exchange-point-and-mark
^X^Y = list-file
^X^[ = complete-command
^X? = list-command
^XA = up-history
^XB = down-history
^XC = forward-char
^XD = backward-char
^XH = beginning-of-line
^XP = delete-char-forward
^XY = end-of-line
^Xc = forward-word
^Xd = backward-word
^Xw = end-of-line
à  = beginning-of-line
à¡ = up-history
ठ= backward-char
ঠ= forward-char
ਠ= end-of-line
à© = down-history
ଠ= delete-char-forward
à´ = backward-word
ච= forward-word

/etc/kshrc

/etc # cat kshrc
case $- in
*i*)
    export SHELL_COLOR_BLUE="print -n \\033[0;34m"
    export SHELL_COLOR_GREEN="print -n \\033[0;32m"
    export SHELL_COLOR_RED="print -n \\033[0;31m"
    export SHELL_COLOR_LIGHTGRAY="print -n \\033[0;37m"
    export SHELL_COLOR_YELLOW="print -n \\033[1;33m"

    export COLOR_BLACK="\\033[0;30m"
    export COLOR_BLUE="\\033[0;34m"
    export COLOR_GREEN="\\033[0;32m"
    export COLOR_CYAN="\\033[0;36m"
    export COLOR_RED="\\033[0;31m"
    export COLOR_PURPLE="\\033[0;35m"
    export COLOR_BROWN="\\033[0;33m"
    export COLOR_LIGHTGRAY="\\033[0;37m"
    export COLOR_DARKGRAY="\\033[1;30m"
    export COLOR_LIGHTBLUE="\\033[1;34m"
    export COLOR_LIGHTGREEN="\\033[1;32m"
    export COLOR_LIGHTCYAN="\\033[1;36m"
    export COLOR_LIGHTRED="\\033[1;31m"
    export COLOR_LIGHTPURPLE="\\033[1;35m"
    export COLOR_YELLOW="\\033[1;33m"
    export COLOR_WHITE="\\033[1;37m"

    if [[ `id -u` -eq 0 ]]; then
        export PS1=`$SHELL_COLOR_RED`'$(hostname -s):'`$SHELL_COLOR_YELLOW`'$(pwd) # '`$SHELL_COLOR_LIGHTGRAY`
    else
        export PS1=`$SHELL_COLOR_BLUE`'$(hostname -s):'`$SHELL_COLOR_GREEN`'$(pwd) $ '`$SHELL_COLOR_LIGHTGRAY`
    fi

esac

PuTTy settings:

enter image description here

Notes that may or may not matter, but could provide background:

The shell is "PD KSH v5.2.14 99/07/13.2". Yes, I have no option to upgrade… it's an embedded system. "Get a modern shell" is not a viable answer.
The operating system is QNX Neutrino 6.4.1.

bind shows the following:

 bind | grep del
^D = eot-or-delete
^H = delete-char-backward
^? = delete-char-backward
^[^H = delete-word-backward
^[d = delete-word-forward
^[h = delete-word-backward
^[^? = delete-word-backward
^XP = delete-char-forward
ଠ= delete-char-forward

infocmp shows the following:

infocmp  #      Reconstructed via infocmp from file:
/usr/lib/terminfo/x/xterm xterm|vs100|xterm terminal emulator,
        am, km, mir, msgr, xenl, xon,
        cols#80, it#8, lines#65, vt@,
        acsc=Oa``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
        bel=^G, blink=@, bold=\E[1m, clear=\E[H\E[2J, cr=^M,
        csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H,
        cud=\E[%p1%dB, cud1=\E[B, cuf=\E[%p1%dC, cuf1=\E[C,
        cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\E[A,
        dch=\E[%p1%dP, dch1=\E[P, dl=\E[%p1%dM, dl1=\E[M, ed=\E[J,
        el=\E[K, el1=\E[1K$<3>, enacs=\E(B\E)0, home=\E[H, ht=^I,
        hts=\EH, ich=\E[%p1%d@, ich1=\E[2~, il=\E[%p1%dL, il1=\E[L,
        ind=^J, is1=\E=\E[?1l, kBEG=\ENn, kCPY=\ENs, kCRT=\ENt,
        kDL=\ENv, kEXT=\ENw, kFND=\ENx, kHLP=\ENy, kOPT=\ENz,
        ka3=\EOs, kb2=\EOr, kbs=^H, kc1=\EOq, kcan=\EOm, kclo=\ENc,
        kclr=\ENa, kcmd=\EOu, kcub1=\E[D, kcud1=\E[B, kcuf1=\E[C,
        kcuu1=\E[A, kdch1=\E[P, kend=\E[9, kf1=\E[11~, kf10=\E[21~,
        kf11=\E[23~, kf12=\E[24~, kf2=\E[12~, kf3=\E[13~,
        kf4=\E[14~, kf5=\E[15~, kf6=\E[17~, kf7=\E[18~, kf8=\E[19~,
        kf9=\E[20~, kfnd=\ENf, khlp=\ENh, khome=\E[8, khts=\ENb,
        kich1=\E[2~, kmov=\ENi, kmrk=\ENm, kmsg=\ENe, knp=\E[6~,
        kopn=\ENo, kopt=\ENk, kpp=\E[5~, kref=\ENl, kres=\ENp,
        krfr=\ENg, krpl=\ENr, krst=\ENj, ksav=\ENq, kslt=\EOM,
        ktbc=\ENd, kund=\ENu, rc=\E8, rev=\E[7m, ri=\EM, rmacs=^O,
        rmam=\E[?7l, rmkx=\E>, rmso=\E[m,
        rs1=\E>\E[1;3;4;5;6l\E[?7h\E[m\E[r\E[2J\E[H, rs2=@,
        sc=\E7,
        setb=\E[4%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m,
        setf=\E[3%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m,
        sgr=\E[0%?%p1%p6%|%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;m,
        sgr0=\E[m, smacs=^N, smam=\E[?7h, smkx=\E=, smso=\E[7m,
        tbc=\E[3g,

stty shows the following:

stty Name:  /dev/ttyp0 Type:  pseudo Opens: 2
+edit +echok +echonl
+osflow  intr=^C  quit=^\ erase=^?  kill=^U   eof=^D start=^Q  stop=^S  susp=^Z lnext=^V   min=01  time=00   pr1=^[   pr2=5B  left=44 right=43
up=41  down=42   ins=40   del=50  home=48   end=59

Best Answer

For Googlers:

Whew. For something that should be so simple, this was hard.

The short solution is use the following to set the delete key (in kshrc or wherever),

bind '^[[3'=prefix-2
bind '^[[3~'=delete-char-forward

And set your PuTTy terminal settings to rxvt instead of Standard.

PuTTy settings

This thing that really helped me get this working was: http://www.mail-archive.com/misc@openbsd.org/msg81796.html

ksh does silly things with the home and end keys. Basically, I couldn't make it tell the difference between Home, End, and Delete at the same time. Whatever was last bound, all three keys would do. Changing what PuTTy sent for these keys helped immensely.

Note: Some folks suggest if you want to see what code the shell is getting when you press a key, type cat, press enter, then push the key. For my shell, this didn't work. I got ~ for all the control keys. What I did instead was press Esc once, then press the key. The control code would show then show up. Use that control code in bind and you're all set.

Related Question