Re: bash completion and spaces
On Mon, 26 Apr 2021 Victor Sudakov wrote:
davidson wrote:
On Sat, 24 Apr 2021 Victor Sudakov wrote:
[dd]
BTW on my current Debian system I don't see the space character in $COMP_WORDBREAKS.
If you have xxd installed, what does xxd show you?
I actually looked with `hd` and expected to see 0x20 there, but
somehow see none of it:
$ echo $COMP_WORDBREAKS | hd
00000000 22 27 40 3e 3c 3d 3b 7c 26 28 3a 0a |"'@><=;|&(:.|
0000000c
Above I count 12 characters piped from echo to hd. The final character
is a newline added by echo, so that leaves 11 characters attributable
to the content of COMP_WORDBREAKS.
But try this, below. It will tell you the length (in characters) of
the content of COMP_WORDBREAKS.
$ echo ${#COMP_WORDBREAKS}
14
So, when you do...
$ echo $COMP_WORDBREAKS | hd
00000000 22 27 40 3e 3c 3d 3b 7c 26 28 3a 0a |"'@><=;|&(:.|
0000000c
...what accounts for the three missing characters (namely SPACE, TAB,
and NEWLINE)?
TLDR: The shell's "word splitting" removes them, because you have not
double-quoted the variable.
Surround the variable with double-quotes, and I expect you will see
that they are the first three characters of the content of
COMP_WORDBREAKS.
$ echo "$COMP_WORDBREAKS" | hd
00000000 20 09 0a 22 27 40 3e 3c 3d 3b 7c 26 28 3a 0a | .."'@><=;|&(:.|
0000000f
For more explanation, see
bash(1), section EXPANSION (esp. subsection "Word Splitting")
https://mywiki.wooledge.org/WordSplitting
https://mywiki.wooledge.org/Arguments
--
Ce qui est important est rarement urgent
et ce qui est urgent est rarement important
-- Dwight David Eisenhower
Reply to: