Suppose I have a script test.sh
that contains
#!/bin/bash
for var in var1 var2;
do
for i in `seq 2`; do
sh test2.sh $var > tmp.sh
cat tmp.sh;
done
done
and I have another script test2.sh
that looks as such
#!/bin/bash
echo "I use the variable here $1"
echo "and again here $1"
echo "even a third time here $1"
Now in my first script what I want to do is to pass the entire content of test2.sh
with the current local variable (i.e. on line six: sh test2.sh $var > tmp.sh
) so if I were to call say sh test2.sh var1
then it would return
I use the variable here var1
and again here var1
even a third time here var1
So I want to pass the entire content of sh test2.sh $var
to a new shell file, but with the argument in place of the variable. Hence the output should be:
I use the variable here var1
and again here var1
even a third time here var1
I use the variable here var1
and again here var1
even a third time here var1
I use the variable here var2
and again here var2
even a third time here var2
I use the variable here var2
and again here var2
even a third time here var2
Thus what I am really wondering is; how do I pass the entire shell with a local argument, to a new, temporary shell script? Really what I wondering is how I run something like this:
for var in var1 var2;
do
for i in `seq 2`; do
sh (sh test2.sh $var)
done
done
Thanks.