CS155 Pipe
Students occasionally ask me why this doesn’t work:
% mkdir foo | cd foo /tmp/pmwiki-bash-script4Btx7a: line 10: cd: foo: No such file or directory
because they think that the pipe symbol (|
) means “and then”.
It doesn’t!
The pipe symbol means:
% echo -e 'my\ndog\nspot' my dog spot % echo -e 'my\ndog\nspot' | sort dog my spot
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.