Linux Shelling Programming Warm-up Example – For Loop

This little program:
1. loop though files in "linuxPractice" directory
2. put file names to a file "new.txt"
3. copy every file to the "new" directory

for i in /usa/programcreek/linuxPractice/*
        if [ -f $i ]
        #check if the file is there by using [-f 4i]                                                                                                                                                                                                               
	  #check file name, that is, exclude path
            echo   $i $filename | cat >> new.txt
 	  #use pipe redirect two file names to new.txt
        cp -p $i /usa/programcreek/linuxPractice/new/$filename
	  #copy file to new directory
Category >> Uncategorized  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
String foo = "bar";

  1. ryanlr on 2014-8-12

    No space between asignment variable and expression!

Leave a comment