mainThe GNU Bourne-Again SHell - Support: sr #109251, Bash completion interaction with...

 
 

sr #109251: Bash completion interaction with quotes

Submitter:  None
Submitted:  Wed 08 Feb 2017 03:47:24 PM UTC
   
 
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  Done
Privacy:  Public Assigned to:  None
Originator Email:  -email is unavailable- Open/Closed:  Open
Operating System:  GNU/Linux
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 17 Jan 2023 09:15:30 PM UTC, comment #2: 

This was changed back in February 2018 as the result of https://lists.gnu.org/archive/html/bug-bash/2018-02/msg00032.html.

Chet Ramey <chet>
Group administrator
Sun 12 Feb 2017 12:06:20 AM UTC, comment #1: 

Well, the issue is (again) mismatched expectations.  The bash
documentation says that when computing COMP_WORDS, the line is
broken into words the way readline does it.  You're expecting it to happen the way bash does it with a non-default $IFS.

I'm not opposed to changing this, but I will have to look at how
it might change whatever the existing versions of bash_completion
expect.

Chet Ramey <chet>
Group administrator
Wed 08 Feb 2017 03:47:24 PM UTC, original submission:  

There is a strange interaction between the completion and the use of single or double quotes in the command line. More precisely, when the quote is preceded by a delimiter, it is treated also as a common delimiter, ignoring that it has the distinctive feature that it opens a string.

This happens quite often when trying to complete commands such as:
`my_command --first-option="text_with_possible_spaces" --second-op<TAB>`

What happens is that COMP_WORDS contains ([my_command] [--first-option] [="] [text_with_possible_spaces" --second-op]), where the brackets delimit each word.

The function "split_at_words" in subst.c seems responsible for this behavior (especially lines 2299-2310 in Bash-4.4 patch 12). When a delimiter (here "=") is encountered, it tries to add as many consecutive delimiters as it can. And since the quotes are in COMP_WORDBREAKS, they are added to this word. And when the completion sees the second quote, it treats it as the opening of a string (since the first quote was ignored), creating the strange word [text_with_possible_spaces" --second-op], that obviously will not give interesting completions.

A solution could be to remove the quotes (' and ") from variable "d2", or to treat them in a specific way in lines 2299-2310. But probably there are other constraints that I am not aware of.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by chet (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-01-17 chet StatusIn Progress Done
    2017-02-12 chet StatusNone In Progress

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code