Below is a script that I created to demonstrate a problem with Bash autocomplete. The problem occurs after pressing CTRL/C inside READ and TRAP function INT.
After pressing CTRL/C, Bash autocomplete only works for files in the current directory. I do have the current directory in my PATH variable among the usual /sbin /bin/ usr/bin, etc. I also checked the output of “shopt” and “set” in the shell before and after experiencing the issue, but I don’t see the difference.
This is a custom Linux (4.20 and 5.9), running bash 4.4.
#!/bin/bash
$( return 0 2>&- )
if [[ $? -ne 0 ]]; then
echo "Source-execution required. Aborted"
exit 1
fi
doit=doit
cleanup()
{
trap - INT
echo; echo "doing all sorts of stuff to unset vars, etc."
unset doit # Abandon further processing.
unset cleanup
}
ctrl_c()
{
echo; echo
echo "Canceled."
cleanup
}
trap "ctrl_c; return" INT
read -r -e -n 1 -p "?"
if [[ "${doit}" ]]; then
echo "you won't see this after ctrl/c"
cleanup
fi
Output is as following:
# gr<tab>
grep groups grubed grubed.sh
# source xx.sh
?^C
Canceled.
doing all sorts of stuff to unset vars, etc.
# gr<tab> -> resolves right into grubed.sh which is in the current directory.