LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-24-2015, 06:05 AM   #1
newuser85
LQ Newbie
 
Registered: Aug 2015
Posts: 15

Rep: Reputation: Disabled
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.
 
Old 09-24-2015, 06:13 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
you do not need to have anything like callcode, just type:
$DIR/bin/gens.ksh $genNbr $genSource $genDest
or probably I misunderstood ...
 
Old 09-24-2015, 06:28 AM   #3
newuser85
LQ Newbie
 
Registered: Aug 2015
Posts: 15

Original Poster
Rep: Reputation: Disabled
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
 
Old 09-24-2015, 06:37 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
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?)
 
1 members found this post helpful.
Old 09-24-2015, 06:41 AM   #5
newuser85
LQ Newbie
 
Registered: Aug 2015
Posts: 15

Original Poster
Rep: Reputation: Disabled
Thanks for your reply. btw its a bash script.

thanks
 
Old 09-24-2015, 08:29 AM   #6
doni
LQ Newbie
 
Registered: Mar 2006
Posts: 27

Rep: Reputation: 1
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
 
1 members found this post helpful.
Old 09-24-2015, 09:02 AM   #7
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,016

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
Quote:
Originally Posted by pan64 View Post
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!
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl Help - Passing args to subs rhugga Programming 2 01-31-2013 07:13 AM
[SOLVED] Passing args from C to NASM WarTurkey Programming 5 01-31-2012 04:19 PM
[SOLVED] Assembly for execve passing args... trist007 Programming 3 08-12-2011 01:05 AM
Passing args in terminal window is OK. but isn't when passing in GNOME launcher why? majrys1962 Debian 0 11-18-2008 06:00 PM
Passing args in an IOCTL neerajb Linux - Software 0 04-20-2006 05:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration