By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,712 Members | 1,958 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,712 IT Pros & Developers. It's quick & easy.

Passing SOME command-line options to another script

P: 2
I have a set of several scripts. One, called "mach-list" lists all machines that match specified criteria (e.g., all Solaris machines). Others (e.g., "mach-run") do things on multiple machines; they call mach-list to get the list of machines.

mach-list has command-line options. When you call mach-run, you can include on mach-run's command line the options for mach-list. How does mach-run know which options to pass to mach-list?

I thought of the following methods.

A marker: e.g., mach-run could have syntax like the following:
mach-run [ mach-list-options // ] [ mach-run-options ] arguments...
"//" is the marker; everything before it is an option for mach-list.
  • I don't want to use "--", because mach-run might want to use "--" for something else.
  • Doesn't have to be "//", but it's easy to type.

Separate file: have a subroutine/module in a separate file that processes mach-list's options:
  • options not related to mach-list will remain in the command line (so mach-run can process them)
  • mach-list, mach-run, etc. will all call/include this subroutine/module
  • the subroutine/module will set environment variables used only by mach-list

Does anyone have a better idea? Thanks.
Jun 6 '10 #1
Share this Question
Share on Google+
5 Replies

Expert Mod 2.5K+
P: 3,503
Can all of your requirements be met in one file, or even let files? You can always fork new processes and have any information found put into a file that can be read in after the forked process exits. Just a thought.


Jun 6 '10 #2

Expert Mod 100+
P: 589

FYI, this Q is cross posted
Jun 6 '10 #3

P: 70
Another possibility is to make a copy of mach-run's @ARGV then pass it directly to mach-list. This might require both scripts to ignore any irrelevant options:

Expand|Select|Wrap|Line Numbers
  1. # inside mach-run
  2. my @argv_copy = @ARGV;
  4. # now process @ARGV
  6. ...
  8. system "mach-list @argv_copy";
Jun 6 '10 #4

P: 2
Regarding numberwhun's answer: I'm not sure what "let files" are, but it sounds similar to the idea of environment variables: a common storage. Files are trickier, because these are not daemons/services but commands, and more than one person might be running them at a time.

cross-posting: is that a problem? I thought DevShed was a separate site from this, though I noticed both sites seem to use the same forum software.

Regarding toolic's answer (copying @ARGV): interesting idea. I'd prefer invalid options be caught. But I'll think about this.

Thanks! (different ideas are still appreciated)
Jun 7 '10 #5

Expert Mod 2.5K+
P: 3,503
First, I meant to say "less" files, sorry. By forking the process, you could do what you need to do and once the fork returns to the current script for processing, it would continue, thus, cutting down on the need for multiple scripts/files.

As for the cross posting, you will find there are a lot of people here who participate in other forums as well. Their letting us know that the question(s) are cross posted allows us to see if an answer was provided prior and if that answer helped or not.


Jun 8 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.