LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 07: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, 07:13 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
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, 07: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, 07:37 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
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, 07: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, 09:29 AM   #6
doni
LQ Newbie
 
Registered: Mar 2006
Posts: 26

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, 10:02 AM   #7
joe_2000
Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 808

Rep: Reputation: 216Reputation: 216Reputation: 216
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 08:13 AM
[SOLVED] Passing args from C to NASM WarTurkey Programming 5 01-31-2012 05:19 PM
[SOLVED] Assembly for execve passing args... trist007 Programming 3 08-12-2011 02:05 AM
Passing args in terminal window is OK. but isn't when passing in GNOME launcher why? majrys1962 Debian 0 11-18-2008 07:00 PM
Passing args in an IOCTL neerajb Linux - Software 0 04-20-2006 06:51 AM


All times are GMT -5. The time now is 10:39 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration