2

I have a strange issue, and really not sure how to search for a similar question on StackExchange.

This is related to Ubuntu 20.04 command-line.

When I press TAB key, which 'autocompletes' appends really weird results as part of the 'input for my current command'.

For instance:

Typing: (cd and pressing TAB afterwards)
....
cd words=("${@:3:2}")
cword="$3"
cur="$3"
cur="$3"
cword="$3"
prev="$3"
words=("${@:3:2}")
stage^C

Same when typing bash + TAB

bash words=("${@:3:2}")
cword="$3"
cur="$3"
cur="$3"
cword="$3"
prev="$3"
words=("${@:3:2}")
^C

Shell autocomplete is behaving strangely recently, not sure how to fix this. (Also apologies again, I really do not know how to phrase this correctly or even find a similar question).

NOTE:

reset only clears the console, but the issue still remains afterwards!

3
  • That looks like the sort of thing you'd get from a misplaced quotation mark or something. Check your ~/.bashrc to see if the text you see (words=...) appear there. Maybe you have syntax error somewhere around there.
    – arensb
    Apr 7, 2021 at 14:18
  • Thanks for hint, unfortunately that's not it.. I verified the ./bashrc file, it remained unchanged since April 5, which was when the server was setup. I know for sure I didn't edit something myself. Apr 8, 2021 at 7:23
  • I had the exact same problem but this answer resolved my issue.
    – Nate
    May 31, 2021 at 17:27

1 Answer 1

3

I assume your shell is Bash. I can replicate your problem by redefining eval like this:

eval() { echo "$1"; }

or similarly. Completion functions use eval. They expect eval to be eval the shell builtin. If eval is tampered with then they may misbehave.

My tests indicate that eval being an alias or an executable does not break completions, so it's most likely a function in your case.

Invoke

type eval

Normally the output should be eval is a shell builtin. If you get eval is a function then invoke

unset -f eval

and check if completions behave better (or at least differently).

You should investigate where the function comes from. A manual method is to check the startup files (~/.bashrc and such) and everything they source. There are better methods. Proceed like this:

shopt -s extdebug   # enable extra debugging info
declare -F eval

This will tell you the line number and the source file. (Finally run shopt -u extdebug to disable debugging.)

The above method should be enough to locate the definition of the function. Just in case, few other methods are here: How to find the file where a bash function is defined.

After you find the definition of this eval function, get rid of it and let eval be the builtin. Notes:

  • Deleting the definition will not automatically fix already running shells. Spawn a new shell; log out and log in; when in doubt, reboot.
  • Deleting the definition will break anything that actually needs the function, so further investigation may be required: for what reason was the function there? Consider renaming instead of deleting (at least initially, temporarily), in case the code in the definition is not expendable.
  • The function may be defined more than once (and the most recently sourced definition wins). If deleting the definition does not bring the builtin back, there's probably a definition left. Repeat the method.

If completions are not fully fixed, examine the output of declare -F and check for other functions that replace builtins (use compgen -b to know what to search for). If needed, analyze them like you just did with eval and fix similarly.

2
  • Thank you, what a technical answer! For some reason, my shell is now fine again this morning (eval is a shell builtin). I will definitely look at this when I experience the issue again! Thanks so much for the in-depth explanation on how to debug. Apr 8, 2021 at 7:29
  • I think it might be a tool (docker/dbdeployer) that also uses autocomplete features, one of those two might be doing something, and unexpected on the shell used. I will give more information if I find anything. Apr 8, 2021 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.