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:
.......
nohup ./Script2 PARAMETER
.......
Script2:
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
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?)
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.
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
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.