Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 18th, 2008, 11:19 AM   #1
moddinati
Newbie
 
Join Date: Jul 2008
Posts: 2
Rep Power: 0 moddinati is on a distinguished road
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.sh

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.

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_rev0

thanks in advance for the help
moddinati is offline   Reply With Quote
Old Jul 18th, 2008, 12:04 PM   #2
moddinati
Newbie
 
Join Date: Jul 2008
Posts: 2
Rep Power: 0 moddinati is on a distinguished road
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
moddinati is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:19 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC