Students occasionally ask me why this doesn’t work:
% mkdir foo | cd foo bash: cd: foo: No such file or directory
because they think that the pipe symbol (
|) means “and then”.
The pipe symbol, when used like this, means:
% alpha | beta
betaat the same time.
alphaup to the input of
This only makes sense if
alpha produces output, and
reads input, e.g.,
% ls -l | more
If you want to execute one command after another, just do so:
% mkdir foo % cd foo
% mkdir foo; cd foo
Note that using semicolon (
;) is no less typing
than just pressing the Enter key.