You can find out what _expand does, when typing
$ type _expand
_expand is a function
_expand ()
{
if [[ "$cur" == \~*/* ]]; then
eval cur=$cur;
else
if [[ "$cur" == \~* ]]; then
cur=${cur#\~};
COMPREPLY=($( compgen -P '~' -u "$cur" ));
[ ${#COMPREPLY[@]} -eq 1 ] && eval COMPREPLY[0]=${COMPREPLY[0]};
return ${#COMPREPLY[@]};
fi;
fi
}
This is a function in the bash completion mechanism. It expands tildes (~) in pathnames. In /etc/bash_completion is a comment about the function:
# Expand ~username type directory specifications. We want to expand
# ~foo/... to /home/foo/... to avoid problems when $cur starting with
# a tilde is fed to commands and ending up quoted instead of expanded.
Try it in a terminal, type:
~<tab><tab>
It will expand to the usernames, for example
~usera ~userb ~userc
type. It wasn't clear to me why I could not call these functions as_function_name [argument], but now I understand that they serve their purpose as autocomplete extensions, and the fact that they appear in my autocomplete is simply because they are declared (but they are not meant to be called directly). – 0x5C91 Sep 29 '15 at 08:50_expandfunction, as all other complete functions, just manipulates theCOMPREPLYarray, based on values of$curwhich contains the completion pattern. – chaos Sep 29 '15 at 08:55