![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jul 2008
Posts: 2
Rep Power: 0
![]() |
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 #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.shthe 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. for example, when I actually run my main script, the sub-script that gets created is #!/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_rev0thanks in advance for the help |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Jul 2008
Posts: 2
Rep Power: 0
![]() |
Re: Creating script within a script
found the solution:
#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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Backup Script :-) | Pizentios | Perl | 18 | Jan 12th, 2006 10:50 AM |
| A simple perl script | satimis | Perl | 3 | Aug 15th, 2005 9:31 AM |
| Firewall Script using IPTABLES | Ravilj | Bash / Shell Scripting | 3 | Mar 9th, 2005 9:09 PM |
| Bash Script Help | pelon | Bash / Shell Scripting | 2 | Feb 28th, 2005 3:58 PM |