I understand needing help and I am not running you down in any way.

When I was a newbie, a long time ago,  I learned to read the man page on commands.  I learned a lot of interesting things from reading the page.  As for me I remember much more if I do the work first.  Some man pages are kind of cryptic in nature.  Then I would google for what I needed,  like: How to tar a file in unix. 

I keep an archive of how2xxx. They are just command lines that I used with a few notes.
As an example I have a file named how2awk  it has examples of how I did it.

Here is an example: of  how2foreach  

____in csh_______________________________________
#!/bin/csh
set infile = "./main_servers"
foreach abc ( `cat $infile` )
       echo "---------------------"
       echo "$abc"
       rsh $abc 'ls /opt/SUNWexplo'
end

_____in bash_______________________________________
#!/bin/bash
## path to input file  
input="lists.txt"
 
## Let us read a file line-by-line using while loop ##
while IFS= read -r line
do
 printf 'Working on %s file...\n' "$line"
done < "$input"

I worked in csh most of the time so a lot of my examples are for csh, this one has both csh and bash examples.  They work in SUN os 4.4 through Solaris 10 I have not tried to run the commands in Ubuntu yet but I am sure it would.

 This is just a few things to think about.  I have to ask my sone a lot of questions about how to do things in Linux. Linux is much easier to learn than Solaris was.  You can do a lot of stuff with GUIs but if you want job security learn to do admin by the command line.  

Joe
P.S.
If you keep good notes of what you did and how to do it, you will never have to rewrite code, just modify what you already have.