Bash completion breaks the content of $_ variable

Bug #1919185 reported by libcha
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
bash (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

In bash, the $_ variable ought to contain the last parameter of previous command. For example:

$ touch aaa bbb
$ cat aaa
$ cat bbb $_

the last line is equivalent to "cat bbb aaa".

However, if I use bash completion to fill some other parameter like this:

$ cat bb<TAB> $_

(where <TAB> denotes hitting the TAB key), the value of the $_ variable is overwritten with some mess, so that the result is: "cat: _filedir: No such file or directory"

I expect this variable not to be overwritten and still contain the value "aaa", co that the command prints out the files bbb and aaa.

This bug seems to be version-wide and usage-wide. I encounter this for many Ubuntu releases, for example, using Kubuntu 20.10. It can be reproduced even in terminal with no Xorg running. The resulting error message differs according to what is being TAB-completed, for example with git command it says: "error: pathspec '__git_main' did not match any file(s) known to git".

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in bash (Ubuntu):
status: New → Confirmed
Revision history for this message
Mike Wescott (wescott) wrote :

This bug can lead to data loss:

$ echo aaa > aaa
$ echo bbb > bbb
$ mkdir tmp
$ mv a<tab> $_
$ mv b<tab> $_

Now the directory tmp is empty and there is bbb has been renamed _filedir. The file aaa is nowhere to be found.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.