From man bash
:
EXPANSION Expansion is performed on the command line after it has been split into words. There are seven kinds of expansion performed: brace expansion, tilde expansion, parameter and vari‐ able expansion, command substitution, arithmetic expansion, word splitting, and pathname expansion. The order of expansions is: brace expansion; tilde expansion, parameter and variable expansion, arithmetic expansion, and command substitution (done in a left-to-right fash‐ ion); word splitting; and pathname expansion.
As you can see, the tilde expansion is performed before the variable expansion, so if you run cd $CATKIN_WS
, the shell will try to find a directory named ~
which doesn't exist.