Take the tour ×  I am trying to get cd to accept a directory
name redirected to it from another command. Neither of these
methods work:  $ echo $HOME | cd $ echo $HOME | xargs cd  This
does work:  $ cd $(echo $HOME)  Why does the first set of
commands not work, and are there others that also fail this way?
share|improve this question By others are you referring to other
commands or other methods to use cd that fail this way? –  David
Kohen Oct 5 '12 at 15:46 @DavidKohen I refer to other commands
–  Jhonathan Oct 5 '12 at 16:49 Some notable examples are
ulimit, umask, popd, pushd, set, export and read. –  David Kohen
Oct 7 '12 at 8:10 add comment  6 Answers  up vote 26 down vote
accepted  cd is not an external command - it is a shell builtin
function. It runs in the context of the current shell, and not,
as external commands do, in a fork/exec'd context as a separate
process.  Your third example works, because the shell expands
the variable and the command substitution before calling the cd
builtin, so that c