if [[ $1 ]]; then ... code else ... code fi
Even though single
[ ] quotes do too in places, use double
[[.
cde <tab> and then bash completing with a matching directory from
/etc. Press
enter to cd into that dir.
Put these three functions in
.bashrc
function cde(){
cd /etc/$1
}
function _etcs() {
local dirs=("/etc/$2"*)
[[ -e ${dirs[0]} ]] && COMPREPLY=( "${dirs[@]##*/}" )
}
complete -F _etcs cde