CS155 Pipe
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”.
It doesn’t!
The pipe symbol, when used like this, means:
% alpha | beta
alpha
and beta
at the same time.
alpha
up to the input of beta
.
This only makes sense if alpha
produces output, and beta
reads input, e.g.,
% ls -l | more
If you want to execute one command after another, just do so:
% mkdir foo % cd foo
or:
% mkdir foo; cd foo
Note that using semicolon (;
) is no less typing
than just pressing the Enter key.
Modified: 2014-06-15T14:39 User: Guest Check: HTML CSSEdit History Source |
Apply to CSU |
Contact CSU |
Disclaimer |
Equal Opportunity Colorado State University, Fort Collins, CO 80523 USA © 2015 Colorado State University |