foo=$*: ^A and DEL are prefixed or removed

2017-11-24 Thread Martijn Dekker
Here's another corner-case bug with assigning $* to a variable (i.e.:
foo=$*). If IFS is empty, the $* expansion removes any $'\001' (^A) and
$'\177' (DEL) characters. If IFS contains a value, each ^A and DEL
character is prefixed by another $'\001'. If IFS is unset, the bug does
not show up at all.

This is another case where quoting the $* (i.e.: foo="$*") works around
the bug, yet it's still a bug.

Test script:

fn() {
foo=$*
printf '%s' "$foo" | od -c | awk 'NR==1 { $1=""; print; }'
}
teststring=$(printf '\001\002\003\177')
for IFS in '' ' ' 'X' ' X'; do
fn "$teststring"
done
unset -v IFS
fn "$teststring"

Expected output (and actual output from every non-bash shell):

 001 002 003 177
 001 002 003 177
 001 002 003 177
 001 002 003 177
 001 002 003 177

Actual output (bash 4.4.12, bash-20171110 snapshot):

 002 003
 001 001 002 003 001 177
 001 001 002 003 001 177
 001 001 002 003 001 177
 001 002 003 177

Actual output (bash 4.3.39, 4.2.53, 4.1.17, 3.2.57):

 001 002 003 177
 002 003
 001 002 003 177
 001 002 003 177
 001 002 003 177

Actual output (bash 2.05b):

 001 002 003
 001 002 003
 001 002 003
 001 002 003
 001 002 003

- Martijn



Re: Problem after removing keybinding for bind -m vi-insert '"jj": "\e\e"'

2017-11-24 Thread Chet Ramey
On 11/20/17 11:25 PM, Clark Wang wrote:
> [STEP 100] # echo $BASH_VERSION
> 4.4.12(4)-release
> [STEP 101] # bind -m vi-insert '"jj": "\e\e"'
> [STEP 102] # bind -X
> "jj": "\e\e"
> [STEP 103] # bind -r jj
> [STEP 104] # bind -X
> [STEP 105] # <-- Here when I press j it still waits for about 1 second
> to show up.
> 

Here's what happens: when you bind "jj", it creates a new keymap to handle
the longer key sequence, and notes that `j' is now ambiguous: it's either
`jj' or `j' when followed by any other character. That's the reason for the
delay.

Removing the binding leaves the new keymap in place, because readline
doesn't check whether removing that binding results in an empty keymap,
which would remove the ambiguity.

Readline doesn't have the internal machinery in place to check for and
remove empty keymaps when removing a key binding. I'll have to look at
what it will take to add.

Chet


-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/