|


| NAVIGATION |
|
Home |
|
Store |
|
|
| INSIDE MAC |
|
Television Shows |
|
Broadcast Shows |
|
Daily News Shows |
|
Special Shows |
|
|
| EVENTS |
|
|
|
|
|
|
|
|
| DAILY TIPS |
|
Design |
|
Mac OS X |
|
Mac OS X UNIX |
|
|
| COMMUNITY |
|
Surveys |
|
|
| NEWS |
|
Current |
|
Press |
|
Archive |
|
|
| FEATURES |
|
Editorial |
|
Dr. Mac |
|
Reviews |
|
Reader Reports |
|
|
| RESOURCES |
|
FAQ |
|
Documentation |
|
Learning Center |
|
MAN pages |
|
Glossary |
|
Tutorials |
|
Tips |
|
Links |
|
|
|

|
|
|
OSXFAQ Mac OS X UNIX Tip-of-the-Day
Scripting One-Liners - Bulk Redirection
We all know how to redirect output to a file using the redirection symbol '>'.
$ ls > file-list
Here's an example in which we redirect the output of many commands in a shell script, and without having to redirect the output of each command individually. Create a sub-shell around the commands who's output you wish to redirect.
$ (
>ls
>df
>cat number-list
>) > out
$
You can use a group-command instead of a sub-shell by replacing
(...) > out
with
{...} > out
Use the same trick to re-direct standard input to a group of commands.
$ cat infile
1234
full
$ { read code; read membership; } < infile
$ echo $code $membership
1234 full
$
Note: use a group-command, not a sub-shell, if you wish to retain the values of variables. A sub-shell is executed by a new instance of the shell, and its environment (including all variable) dies when the sub-shell completes.
|


|
Copyright © 2000-2010 Inside Mac Media, Inc. All rights reserved. |
Apple assumes no responsibility with regard to the selection, performance, or use of the products or services. All understandings, agreements, or warranties, if any, take place directly between the vendors and prospective users. |
| Apple, the Apple logo, Mac, PowerMac G4, PowerMac G5, Xserve, Xserve RAID, PowerBook, iBook, Airport, AirPort Extreme, iMac, eMac, iLife, iMovie, iCal, iPhoto, iTunes, QuickTime, FireWire, iPod, iSight, AppleWorks, Macintosh, Jaguar, Panther, Mac OS, Mac OS X and Mac OS X Server are trademarks of Apple Computer, Inc. |
|