LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Passing a script file with its associated args (https://www.linuxquestions.org/questions/linux-newbie-8/passing-a-script-file-with-its-associated-args-4175554378/)

newuser85 09-24-2015 06:05 AM

Passing a script file with its associated args
 
Hi All,

I have a basic doubt about passing args to a script.

Is it possible to send a script file along with its associated args as a arg to a function. the snippet is as below.


callCode $DIR/bin/gens.ksh $genNbr $genSource $genDest

Please advice. Will this work.

Thanks.

pan64 09-24-2015 06:13 AM

you do not need to have anything like callcode, just type:
$DIR/bin/gens.ksh $genNbr $genSource $genDest
or probably I misunderstood ...

newuser85 09-24-2015 06:28 AM

Hi,

thanks for your reply.

callcode is a method/function for which gens.ksh is being passed as an arg.

gens.ksh requires three arguments $genNbr $genSource $genDest.

Hope I made clear what is my query (Is it possible to send a script along with its own args as a argument to another function/method). Please advice.

thanks

pan64 09-24-2015 06:37 AM

That is what I trying to explain: you do not need to do anything, just write:
gens.ksh arg1 arg2 arg3
you do not need any function to do that.
But you can have:
Code:

function callCode {
"$@"
}

that will execute the first argument as a script or app and will pass the following ones to it


(by the way what kind of language is it?)

newuser85 09-24-2015 06:41 AM

Thanks for your reply. btw its a bash script.

thanks

doni 09-24-2015 08:29 AM

You can call the current script with $BASH_SOURCE and the arguments of the current script with $1 (first one) $2 (second one) etc - so maybe something like:

callCode $BASH_SOURCE $1 $2 $3
might work

joe_2000 09-24-2015 09:02 AM

Quote:

Originally Posted by pan64 (Post 5424957)
But you can have:
Code:

function callCode {
"$@"
}

that will execute the first argument as a script or app and will pass the following ones to it

nice!


All times are GMT -5. The time now is 09:53 PM.