Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • Thank you. It is very important to know if the word being completed is preceded by a quotation mark and which one of the two possible quotation marks, as this will determine which characters will need escaping in the word. This can only be done by inspecting COMP_LINE. I find still almost impossible to apprehend all these questions from bash documentation. For example, abc"defghi" is a single word. However, if abc"def is presented to bash completion, $2 will be only def. If one wants to complete abc"def to abc"defghi", a very complicated analysis of COMP_LINE must be performed. Commented Jul 12, 2024 at 13:51
  • $2 holding only def in abc"def is not confusing when you consider the variable COMP_WORDBREAKS and inspect it. In Bash 5.2.26, executing printf "%s" "$COMP_WORDBREAKS" | od -t a gives 0000000 sp ht nl " ' @ > < = ; | & ( :, where the first three characters are space (sp), tab (ht) and newline (nl). Commented Jul 12, 2024 at 17:12
  • I updated the answer by adding a solution based on a related (but in a way reverse from this one) question, using -W option and COMP_WORDS/COMP_CWORD. Commented Jul 12, 2024 at 17:44