bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bash command completion has a problem with sudo command


From: Hyunho Cho
Subject: bash command completion has a problem with sudo command
Date: Mon, 22 Aug 2022 15:10:05 +0900

Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -flto=auto -ffat-lto-objects -flto=auto
-ffat-lto-objects -fstack-protector-strong -Wformat
-Werror=format-security -Wall
uname output: Linux EliteBook 5.15.0-43-generic #46-Ubuntu SMP Tue Jul
12 10:30:17 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.1
Patch Level: 16
Release Status: release

##############################################################

when command completion function start running there are three
variables automatically setting

bash$ hello foo ba[tab]
$1 (command):   hello
$2 (current):        ba
$3 (previous):      foo

bash$ echo -n "$COMP_WORDBREAKS" | od -a
0000000  sp  ht  nl   "   '   @   >   <   =   ;   |   &   (   :

bash$ hello --opt foo:[tab]        # ":" is a member of $COMP_WORDBREAKS
$1 (command):   hello
$2 (current):        (empty)         # default behavior
$3 (previous):      foo

bash$ sudo hello --opt foo:[tab]         # using sudo command
$1 (command):   hello
$2 (current):        :          <----- not empty
$3 (previous):      foo

In cases where the $2 variable's value is a member of the
$COMP_WORDBREAKS variable
then the $2 value is empty by default and has to use the
${COMP_WORDS[COMP_CWORD]} variable for that value.
I think this is good for making the completion function simpler.
but if I use the sudo command in front of the hello command then the
$2 value is not empty.
this ends up can not use $2 variable and force to use
${COMP_WORDS[COMP_CWORD]} variable



reply via email to

[Prev in Thread] Current Thread [Next in Thread]