CS155: Introduction to Unix

Fall 2017


See this page as a slide show

Pipe vs. Semicolon

CS155 Pipe

Don’t do this

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!

What does the pipe do?

The pipe symbol, when used like this, means:

    % alpha | beta

This only makes sense if alpha produces output, and beta reads input, e.g.,

    % ls -l | more

Do this, instead

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.

Modified: 2014-06-15T14:39

User: Guest

Edit History Source
Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2015 Colorado State University
CS Building