• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 345
  • Last Modified:

Help Needed with Bash Script

Can anyone explain the below bash script line-by-line.

#!/usr/bin/bash 

find -type d > dir.lst
  while
	read i
  do
     cd $1/$i
     mv * $1/../done/$i/.
     cd $1/../stud
     find . -name "*.xml" -exec ./stud_filter.sh {} \;
     echo \$ fwdXML "*.xml"|/usr/bin/ftp sid.student.com
     mkdir $1/../done/stud/$i 2>/dev/null
     mv * $1/../done/stud/$i/.
  done < dir.lst
  rm dir.lst

Open in new window

0
gaugeta
Asked:
gaugeta
1 Solution
 
farzanjCommented:
#!/usr/bin/bash  #Must be first line-->Called shebang. Location of Bash interpreter 

#Finding all the directories -- type d means directories, stored to file dir.lst
find -type d > dir.lst

#Reading file dir.lst line by line, each line then stored in variable i
  while	read i
  do

    #change directory, $1 is command line parameter, $i is read from file
     cd $1/$i

     #move file from given location to the done folder.  Two dots mean parent directory
     mv * $1/../done/$i/.

     #Change directory again  .. parent directory of $1 to child stud
     cd $1/../stud

     #finding files with xml extension and passing them to the script stdu_filter.sh
     find . -name "*.xml" -exec ./stud_filter.sh {} \;

     #pass/pipe $fwdXML "xml filename" to ftp
     echo \$ fwdXML "*.xml"|/usr/bin/ftp sid.student.com

     #Make directory, dump error messages
     mkdir $1/../done/stud/$i 2>/dev/null

     #Another move as explained
     mv * $1/../done/stud/$i/.
  done < dir.lst

  #cleanup step, remove this tmp file
  rm dir.lst

Open in new window

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now