CS155: Introduction to Unix

Spring 2018

Pipe

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
/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!

What does the pipe do?

The pipe symbol means:

% echo -e 'my\ndog\nspot'
my
dog
spot
% echo -e 'my\ndog\nspot' | sort
dog
my
spot

Do this, instead

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.

User: Guest

Check: HTML CSS
Edit History Source

Modified: 2017-12-26T16:52

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