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

UNIX in a Nutshell: System V Edition

UNIX in a Nutshell: System V EditionSearch this book
Previous: Reference: fi Chapter 4
The Bourne Shell and Korn Shell
Next: Reference: function
 

for



for

 

x

 [

in

 

list

]


do


     

commands

 


done

For variable x (in optional list of values) do commands . If list is omitted, "$@" (positional parameters) is assumed.

Examples

Paginate files specified on the command line; save each result:

for file do
     pr $file > $file.tmp
done

Search chapters for a list of words (like fgrep -f ):

for item in `cat program_list`
do
     echo "Checking chapters for"
     echo "references to program $item..."
     grep -c "$item.[

co

]" chap*
done

Extract a one-word title from each file and use as new filename:

for file do
     name=`sed -n 's/NAME: //p' $file`
     mv $file $name
done


Previous: Reference: fi UNIX in a Nutshell: System V Edition Next: Reference: function
Reference: fi Book Index Reference: function

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










??????????????@Mail.ru