home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 9.16 Command Substitution Chapter 9
Saving Time on the Command Line
Next: 9.18 Process Substitution
 

9.17 Handling Lots of Text with Temporary Files

Sometimes, you need to execute a command with a long list of files for arguments. Here's an easy way to create that list without having to type each filename yourself - put the list in a temporary file (21.3 ) :



`...`
 
% ls > /tmp/mikel


% vi /tmp/mikel

 
 ...edit out any files you don't want...

% process-the-files 

`cat /tmp/mikel`


% rm /tmp/mikel

I added the vi step to remind you that you can edit this list; for example, you may want to delete a few files that you don't want to process.

Possible problems: if the list is long enough, you may end up with a command line that's too long for your shell to process. If this happens, use xargs (9.21 ) . If your system doesn't have xargs , there are other workarounds (9.23 ) doesn't that should solve the problem. Article 9.24 shows another way to use temporary files for commands.

- ML


Previous: 9.16 Command Substitution UNIX Power Tools Next: 9.18 Process Substitution
9.16 Command Substitution Book Index 9.18 Process Substitution

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System