The behavior you describe is likely caused by bash-completion.
(What follows is based on the current version of the package (2.9), but it will be reasonably accurate for the 2.1 version you have too).
bash-completion provides a set of completion specifications (compspec) that the Readline library uses to complete words that are supplied as arguments to commands in Bash. They are defined using the complete
builtin command, usually in the form:
complete -F function command
For the export
builtin, the function _export
is defined in /usr/share/bash-completion/completions/export
.
When the word to complete includes (or ends in) a =
, _export
tries to complete it (the part to the right of the first =
, actually) as a file or directory name; when the word to complete does not include a =
, it tries to complete it as a variable name. Since the Readline library starts a new completion every time it runs across one of the characters listed in the COMP_WORDBREAKS
variable (unless the character is escaped), which usually includes :
, completion stops working after the first colon you append to a variable's value because, at that point, the word to complete is not including (or ending in) a =
anymore.
(Note, incidentally, that file/directory name completion starts working again if you write export myvar=/usr/:othervar=
and hit Tab).
bash-completion indeed has its own mechanism for handling special cases. For instance, :
is correctly dealt with by the compspec for scp
, which interprets what is on the right hand of a colon as a remote path. The same is not applied to export
, though.
Readline's default behavior, which is triggered when a compspec for the current command is not found, is ultimately to attempt filename completion. That is why completion of path2
in export var=/path1/:/path2/
works when bash-completion is not installed or otherwise disabled (remember that every colon starts a new completion).
What can you do, then? You have some alternatives:
File a feature request to bash-completion on GitHub.
Define your own completion function for export
.
First, copy the compspec to the user completion file (which likely doesn't exist yet):
$ cat /usr/share/bash-completion/completions/export >>~/.bash_completion
Then edit ~/.bash_completion
, changing complete -F _export export
into complete -F _export -o default export
. This instructs Readline to attempt the default completion when export
's specific compspec gives no results.
Use the default completion, instead of the one provided by bash-completion.
Add to your ~/.bashrc
:
complete -o default -o bashdefault export
(Suggestion from bash-completion's FAQ). The downside is that you lose the ability to complete variable names and export
options.
If you are willing to become familiar enough with bash-completion, define your own _export
function, as in (2), by editing the provided one to let it handle :
specially.
export mypath=/path/1:/path/2
works (even after any:
) on various Bash versions -- I don't have any Bash 4.3, though.export myvar=
; with version 1.3,export mypath=/path/1:/path/2
has working auto-completion for/path/2
, too. Please, add your bash-completion (and operating system) version to your question.