27.08.2015 Views

Advanced Bash−Scripting Guide

Advanced Bash-Scripting Guide - Nicku.org

Advanced Bash-Scripting Guide - Nicku.org

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Advanced</strong> <strong>Bash−Scripting</strong> <strong>Guide</strong><br />

fi<br />

# Thanks, S.C.<br />

Processes may execute in parallel within different subshells. This permits breaking a complex task into<br />

subcomponents processed concurrently.<br />

Example 20−3. Running parallel processes in subshells<br />

(cat list1 list2 list3 | sort | uniq > list123) &<br />

(cat list4 list5 list6 | sort | uniq > list456) &<br />

# Merges and sorts both sets of lists simultaneously.<br />

# Running in background ensures parallel execution.<br />

#<br />

# Same effect as<br />

# cat list1 list2 list3 | sort | uniq > list123 &<br />

# cat list4 list5 list6 | sort | uniq > list456 &<br />

wait<br />

# Don't execute the next command until subshells finish.<br />

diff list123 list456<br />

Redirecting I/O to a subshell uses the "|" pipe operator, as in ls −al | (command).<br />

A command block between curly braces does not launch a subshell.<br />

{ command1; command2; command3; ... }<br />

Chapter 20. Subshells 269

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!