The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Pass parameter into script alfredo Shell Programming and Scripting 2 04-08-2008 06:40 PM
how can i pass parameter with spaces to csh script umen Shell Programming and Scripting 1 03-19-2008 08:33 AM
How to pass a parameter from one Shell-script to another Shell-script subodhbansal Shell Programming and Scripting 2 09-22-2007 02:19 AM
PASS parameter to AWK unisam UNIX for Dummies Questions & Answers 2 05-14-2004 06:51 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-04-2002
Registered User
 

Join Date: Jan 2002
Posts: 4
Exclamation Pass Parameter to Another Script

I have a piece of code that I do not want to continuously repeat. I want to call script2 from script1 and pass a parameter. Here is an example:

Script1:
Code:
.......
nohup ./Script2 PARAMETER
.......
Script2:
Code:
if [ -z $1 ] 
# Checks if any params. 
then 
  echo "No parameters passed to function." 
  return 0 
else 

    PARAM = $1
    ftp -vn xxx.xxx.xxx.xxx  <<- eof
    user pswd
    bin
    mput * 
    bye
    eof
  fi

fi
added code tags for readability --oombera

Last edited by oombera; 02-18-2004 at 12:57 PM.
Forum Sponsor
  #2 (permalink)  
Old 04-04-2002
Registered User
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
Not 100% sure what you're asking here...but if It's what I think it is....

Run script 1 like this......

./Script1 Hello

In Script 1 - you have

nohup ./Script2 $1

Then script 2 is the same.

Why you would want 2 scripts here I'm not sure (but thismay just be for the example?)

If this really is your script - then you could just use

nohup ./Script2 Hello

Because all you are doing is running script2 in nohup and passing it the same variable. Up to you! (Not sure what you are actually doing with the variable though?)
__________________
Pete
  #3 (permalink)  
Old 04-05-2002
Registered User
 

Join Date: Jan 2002
Posts: 4
Script1 is invoked by process. It is not manual. When this process makes Script1 run I want it to pass a parameter to Script2. There is more code in Script1 than what I am showing. I want Script2 to contain code outside of Script1 because there are 13 other scripts that use the code in Script2. I do not want to have to maintain the code in 13 scripts.

The code inside Script1 is:
Code:
..............
..............
nohup ./Script2 $ARE 
..............
..............
Then the code I have inside Script2 is:
Code:
if [ -z $1 ] 
# Checks if any params. 
then 
echo "No parameters passed to function." 
return 0 
else 
  
  PARAM = $1 
  if [ ! -r $INDIR/$PARAM/* ]
  then
    #NO FILE IN THE IN DIRECTORY
  else
    ftp -vn xxx.xxx.xxx.xxx <<- eof 
    user pswd 
    bin 
    mput * 
    bye 
    eof 
  fi 

fi
added code tags for readability --oombera

Last edited by oombera; 02-18-2004 at 12:58 PM.
  #4 (permalink)  
Old 04-05-2002
Registered User
 

Join Date: Jan 2002
Posts: 4
I fixed it. My problem was in Script2.

Thanks
  #5 (permalink)  
Old 04-05-2002
Kelam_Magnus's Avatar
Unix does a body good.
 

Join Date: Aug 2001
Location: DFW McKinney, TX,
Posts: 1,069
CASE and modular scripting

Just FYI.

I did something similar to this in a very old, long time ago, homework assignment.

I had a script that processed incoming data from the command line, which could come from another process. Then I had a CASE statement that called certain outside scripts depending on what the data was.

I believe in modular programming, so that you can remove or change one part of a large script, or several related scripts, without a major modification of the overall script. This group of scripts I created had 10 total scripts.

Even though you fixed your problem, try this in future scripting.

__________________
My brain is your brain
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:00 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0