If there's a file called example.txt with contents:
Foo
Bar
Baz
Goo
then I need to generate a shell script that has commands to reconstruct example.txt on another machine:
echo "Foo" >> example.txt
echo "Bar" >> example.txt
echo "Baz" >> example.txt
echo "Goo" >> example.txt
I use for i in * to search a directory and conduct the above operation on every file that's not binary. Suppose i points to example.txt now, as the above example shows. I used sed to extract the contents of the files line by line. The question is how to use the result extracted by sed as the argument of echo?
I tried:
number=`wc -l < $i`
count=1
while [ $count -le $number ]
do
tmp=`sed -n "$count,1p" $i`
echo ' echo "$tmp" >> $i ' >> bundle.sh
done
Here tmp is the content of each line, but $tmp didn't evaluate in echo.
Actually the purpose of doing so is to transfer a directory containing various files and subdirectories which also contain files to another machine through simple email. Only bundle.sh needs to be transferred. So when the shell script bundle.sh is run on the other machine, the whole directory will be constructed there. I'm writing a script that can generate the bundle.sh script. And of course this needs to be done recursively since there're subdirectories, but ignore it for now. Thanks.
Here is a url to the full description of the task: