Visit Our UNIX and Linux User Community


Pass Parameter to Another Script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Pass Parameter to Another Script
# 1  
Old 04-04-2002
Error 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 04:57 PM..
# 2  
Old 04-04-2002
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?)
# 3  
Old 04-05-2002
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 04:58 PM..
# 4  
Old 04-05-2002
I fixed it. My problem was in Script2.

Thanks
# 5  
Old 04-05-2002
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.

Smilie
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #629
Difficulty: Easy
In PHP, False == 0;
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How pass the input parameter to a file in the script ?

OS version: RHEL 6.7 myTextFile.txt file is referred within Script1.sh script, I only execute Script1.sh and I want the input variable to be passed inside myTextFile.txt . Any idea how I can do this ? $ cat script1.sh cat myTextFile.txt $ cat myTextFile.txt $1 Requirement1.... (4 Replies)
Discussion started by: kraljic
4 Replies

2. Shell Programming and Scripting

Pass script with parameter in korn shell script

I have written a script which will take input parameter as another script. However, if the script passed as input parameter has parameters then this script doesn't work. I have a script b.ksh which has 1 and 2 as parameters I have a script c.ksh which has 3,4 and 5 as parameters vi a.ksh... (1 Reply)
Discussion started by: Vee
1 Replies

3. Post Here to Contact Site Administrators and Moderators

Unable to pass shell script parameter value to awk command in side the same script

Variable I have in my shell script diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk -F'~' ''$2 == "$id"' {print $0}' > $new I could see value of $id is not passing to the awk... (0 Replies)
Discussion started by: Ashunayak
0 Replies

4. Shell Programming and Scripting

Pass parameter to nawk from shell script

I need to parse log files using nawk, but I'm not able to pass script input argument (date) to nawk, for example: ------------ #!/bin/ksh read date nawk -F, '{if($1==date) print $4" "$5}' ------------- Is there a way to pass an argument to nawk from shell script. Many thanks... (8 Replies)
Discussion started by: samer.odeh
8 Replies

5. UNIX for Advanced & Expert Users

How to use parameter in sql script pass from unix script?

Hi, I am unable to use parameter in sql script passed from unix script. my sql script CREATE_SBI_LIST_GROUP.sql is like this - ------------------------------- SELECT SDS.ID "SO_ID", SDS.SO a1, sgp.sga__code SGA_CODE, FROM sga sga,sales_genl_provision sgp , comm_product_condn cpc... (2 Replies)
Discussion started by: apskaushik
2 Replies

6. Shell Programming and Scripting

How to pass string as a parameter in a script

Hi friends. i am newbie to shell scripting. I need to create a script where i will be passing 2 parameters to the script and based on that it should work. For ex: start_proc a 2 or start_proc b 2 start_proc a 2 --- this should bring up 2 processes as i define inside the script. start_proc... (2 Replies)
Discussion started by: friscouser
2 Replies

7. UNIX for Advanced & Expert Users

Pass parameter to the main script from wrapper script

Hi, I am writing a wrapper script(wrap_script.sh) to one of the main scripts (main_script.sh) The main script is executed as following: ./main_script.sh <LIST> <STARTDATE> <ENDDATE> looks for a parameter which is a LIST(consists of different list names that need to be processed), START/END... (0 Replies)
Discussion started by: stunnerz_84
0 Replies

8. Shell Programming and Scripting

What is the maximum number of parameter we can pass to a shell script function?

what is the maximum number of parameter we can pass to a shell script function (8 Replies)
Discussion started by: alokjyotibal
8 Replies

9. Shell Programming and Scripting

Pass parameter into script

I would like to write a scirpt a.sh that it first checks the first parameter of the input. If it fulfill some condition ,then run an executable program b by using all the parameter. ie. > ./a.sh 10 20 30 40 50 Then a.sh first checks the first parameter, 10, if it mathes the requirement, then... (2 Replies)
Discussion started by: alfredo
2 Replies

10. Shell Programming and Scripting

how can i pass parameter with spaces to csh script

Hello all i need to pass to my shell script parameter that looks like "2 3 3" inside the script i need to use this string that looks like this "2 3 3" but when i try to print the script im getting syntax error , this is my script : set s = $1 echo $s (1 Reply)
Discussion started by: umen
1 Replies

Featured Tech Videos