Results 1 to 3 of 3
Hello,
I'm trying to create a shell script that creates other shell scripts. For example I have the following code within my main script
Code:
#Make script to run DFC
...
- 07-18-2008 #1Just Joined!
- Join Date
- Aug 2007
- Posts
- 5
Creating script within a script
Hello,
I'm trying to create a shell script that creates other shell scripts. For example I have the following code within my main script
the problem is certain variables, such as those like $#,$1,$2, etc. are replaced with the values of those in the main script. Is there a way I can actually have the exact phrase "$#" or "$1" in my second script.Code:#Make script to run DFC cat > run_dfc.sh << EOS #!/bin/bash ## ------------------------------------------------------------ # User defined functions # ------------------------------------------------------------ usage () { echo echo "Usage: `basename $0` <numClusters>" echo } # ------------------------------------------------------------ # Check command-line arguments # ------------------------------------------------------------ if [ $# != 3 ]; then usage exit 1 fi C=$3 L=$1 N=$2 ./dfc_lac --nproc $num_processors --stats $stats $filename $C EOS chmod +x run_dfc.sh
for example, when I actually run my main script, the sub-script that gets created is
thanks in advance for the helpCode:#!/bin/bash ## ------------------------------------------------------------ # User defined functions # ------------------------------------------------------------ usage () { echo echo "Usage: runOnce.sh <numClusters>" echo } # ------------------------------------------------------------ # Check command-line arguments # ------------------------------------------------------------ if [ 5 != 3 ]; then <--------this should be "$# != 3" usage exit 1 fi C=10000 <--------this should be "C=$3" L=CS_002 N=2 ./dfc_lac --nproc 20 --stats 6 CS_002_10000_rev0
- 07-18-2008 #2Just Joined!
- Join Date
- Aug 2007
- Posts
- 5
Found the solution:
Code:#Make script to run DFC cat > run_dfc.sh << EOS #!/bin/bash ## ------------------------------------------------------------ # User defined functions # ------------------------------------------------------------ usage () { echo echo "Usage: `basename $0` <numClusters>" echo } # ------------------------------------------------------------ # Check command-line arguments # ------------------------------------------------------------ if [ \$# != 3 ]; then usage exit 1 fi C=\$3 L=\$1 N=\$2 ./dfc_lac --nproc $num_processors --stats $stats $filename $C EOS chmod +x run_dfc.sh
- 07-19-2008 #3Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
I'd use echo to generate the file, not cat and then you can use single-quoting to hide all the variables without having to do every one individually
Saves exec-ing a process, too.Code:echo >run_dfc.sh '#!/bin/bash stuff more stuff echo $HOME echo $PWD last stuff'


Reply With Quote