[RESOLVED] How I pass in my command-line variables disgusts me

Hello,
What I'm trying to do is to make an easily configurable script that the user can run with just a few basic command line variables (some of our users are not programmers.)  Now, here's my problem, when it comes to extracting the variables from the command line, it's kind of messy.  Lets say I have the following command:
$ ./hl_script.sh --config-file=config_abc.txt --rate=5000 --data-dump=/opt/dump_area -v
"-v" means verbose
Now, given the weird arrangement of the different types of command line arguments, I'd like to extract the salient parts of the information that I care about.  However, at this moment, all I have is the "cut" command which can easily get into undefined behavior territory should the user misstype an input.  I would love to know how you have done this and what your approach to this problem is.
This is the code that I have so far:
# this is where we run the initial test and check if the user entered the
# help flag in order to see how to properly use this application.
if [ $# -gt 1 ]; then
for argument in $@
do
if [ $argument = "--help" ]; then
echo "Here is how you would use this software and the flags that would"
echo " be useful."
echo " --help"
echo " Brings up this display and shows a listing of the options"
echo " that can be used to better utilize this app."
echo ""
echo " --config-file=N"
echo " Specify the config file that we'd like to use."
echo ""
exit 0
elif [ `cut $argument | cut -d'=' -f 1` = "--config-file" ]; then
# read-in the config file that we specified and then proceed to set a
# bunch of environment variables that we need.
echo "stuff..."
fi
done
fi
Last edited by publicus (2014-05-13 13:13:43)

ewaller wrote:
I know your sample code is Bash, but you may want to consider doing it in Python and using this library
Here is a simple Python program I wrote that uses the library:
ewaller$@$odin ~/devel/python 1004 %./sieve.py
Usage: sieve.py [options] arg
sieve.py: error: incorrect number of arguments
ewaller$@$odin ~/devel/python [2]1005 %./sieve.py 10
2 3 5 7
ewaller$@$odin ~/devel/python 1006 %./sieve.py --help
Usage: sieve.py [options] arg
Find prime numbers using a sieve of Eratosthenes
Options:
-h, --help show this help message and exit
-v, --verbose
ewaller$@$odin ~/devel/python 1007 %./sieve.py 10 -v
removing 4
removing 6
removing 8
removing 10
removing 6
removing 9
removing 10
2 3 5 7
ewaller$@$odin ~/devel/python 1008 %cat sieve.py
#! /usr/bin/python
Implement a sieve of Eratosthenes
from optparse import OptionParser
def main():
#Handle all the command line nonsense. We need a number as an argument
usage = "%prog [options] arg"
description = "Find prime numbers using a sieve of Eratosthenes"
parser = OptionParser(usage=usage,description=description)
parser.add_option("-v", "--verbose", action="store_true", dest="verbose")
(options, args) = parser.parse_args()
if len(args) != 1:
parser.error("incorrect number of arguments")
try:
maxval=eval(args[0])
except:
parser.error ("Argument is not a number")
# Here is the sieve
a=[x for x in range(0,maxval+1)]
for count in range(2,int(maxval/2)+1):
if a[count]:
for i in range(count*2,maxval+1,count):
a[i]=0
if options.verbose:
print ("removing %i"%i)
# and report the results
wrap=0
for count in range(2,len(a)):
if a[count]:
print (count,end=" ")
wrap += 1
if (wrap == 5):
print()
wrap = 0
print ()
if __name__ == "__main__":
main()
ewaller$@$odin ~/devel/python 1009 %
The thing is, I already have some shell code written that works, so I don't want to re-write (and re-test) that.

Similar Messages

  • How to pass arguments from command-line to Point(x,y)

    Hi guys, I'm a beginner. i'm trying to figure this out 'how to pass the arguments from command-line to Point(x,y)'. See below is the code that i have written. But it appears eror. Is there anyone can help me to figure this out?
    class day5FourDPoint {
    int a = 0;
    int b = 0;
    int c = 0;
    int d = 0;
    day5FourDPoint rect(Point AB, Point CD) {
    a = AB.x;
    b = AB.y;
    c = CD.x;
    d = CD.y;
    return this;
    void printout() {
    System.out.println("Four Dimension : " + a + b + c + d);
    public static void main(String[] arguments) {
    day5FourDPoint FD = new day5FourDPoint();
    FD.rect(arguments);
    if (arguments.length > 1 & arguments.length < 4) {
    for (int i=0; i < arguments.length; i++) {
    FD=Integer.parseInt(arguments);
    FD.printout();
    }

    I don't use VBS so this is just a guess based on what I have read in this forum. I think when you are passing an 'array' to javascript it needs to be a variant data type. My guess your arguments are not making it to the javascript because it it the wrong data type.

  • How to pass arguments from command line to the .jsx

    Hi, I have a .jsx file that does some scripting with photoshop. I would like to be able to call that script from the command line and pass some arguments. I have been going off of the forum at http://support.muse.adobe.com/thread/290023, mainly the last post. Here it is ...
    command line example : runjavascript.vbs c:\mydirectory\test.jsx arg0 arg1 arg2 arg3
    =====start runjavascript.vbs ===============
    Set vbsArguments = WScript.Arguments
    If vbsArguments.Length = 0 Then
    WScript.Echo "Argument(0) is `your script to execute"
    WScript.Echo "Arguments(0+n) are passed to your script as argument(0) to argument(n-1)"
    Else
    ReDim jsxArguments(vbsArguments.length-2)
    for i = 1 to vbsArguments.length - 1
    jsxArguments(i-1) = vbsArguments(i)
    Next
    Set photoshop = CreateObject( "Photoshop.Application" )
    photoshop.BringToFront
    'DoJavaScript has 3 parameters
    ' syntax DoJavaScript(arg[0], arg[1], arg[2]]
    'arg[0] == javascript file to execute, full pathname
    'arg[1] == an array of arguments to past to the javascript
    'arg[2] == AiJavaScriptExecutionMode: aiNeverShowDebugger = 1,, aiDebuggerOnError = 2 aiBeforeRunning = 3
    ' only use 1
    Call photoshop.DoJavaScriptFile( vbsArguments(0), jsxArguments, 1)
    End IF
    =====end runjavascript.vbs ===============
    =======start test.jsx ====================
    #target photoshop
    for( n = 0 ; n < arguments.length; n++ ){
    alert("argument("+ n+")= " + arguments[n]);
    =======end test.jsx ====================
    In summary, it calls a VBScript from the command line and passing args to the VBScript where it will run the .jsx and pass along the args to the .jsx. This is all seems to work, except that the args never make it from the command line into the .jsx and I'm having trouble narrowing down why.
    I know the args are getting into the VBScript from the command line because I can successfully print them out using WScript.Echo. The VBScript then takes the args and makes a new array called jsxArguments which just holds the arguments that are to be passed on to the .jsx as the second argument in the DoJavaScriptFile().
    I cannot tell if the jsxArguments is correct or not. I added an isobject(jsxArguments) check in the VBScript which fails, but if I do a WScript.Echo jsxArguments(0) it will correctly print out the contents of the array at that position.
    I know that the args are not getting into the .jsx because I added a line alert(arguments.length) which prints out 0.
    Any help would be greatly appreciated. Thanks.

    I don't use VBS so this is just a guess based on what I have read in this forum. I think when you are passing an 'array' to javascript it needs to be a variant data type. My guess your arguments are not making it to the javascript because it it the wrong data type.

  • How to set SAXParser at command-line interface to create a large XML file

    Hi,
    I am trying to create a large XML file (more than 50 MB) by selecting from Oracle database but failed because of "out of memory" error. According to "Oracle XML Developer Guide", we should use SAXParser to parsing a large XML file. But there is no example to show how to set SAXParser at command-line
    Following is what I use to get xml files. It works only when the file is small.
    java OracleXML getXML -DateFormat -withDTD -rowsetTag PO_HDR -conn
    "jdbc:oracle:oci8:@server_name" -user "ID/password" "select * from table_name"
    When I set SAXParser at the way below,
    java oracle.xml.parser.v2.SAXParser OracleXML getXML -DateFormat -withDTD -rowsetTag PO_HDR -conn
    "jdbc:oracle:oci8:@server_name" -user "ID/password" "select * from table_name"
    it failed with the error message: "In class oracle.xml.parser.v2.SAXParser: void main(String argv[]) is not defined"
    Does anyone know how to solve the problem? I'll be appreciated very much for your help.
    Yi

    here are my ideas.
    register the xml schema.
    using xmldom, generate the desired xml output and return as xmltype.
    then you can use something like this to check.
    declare
    xmldoc xmltype ;
    begin
       -- populate xmldoc from you xmldom function
       -- validate against XML schema
       xmldoc.isSchemaValid(schema_url, root_element);
       if xmldoc.isSchemaValid = 1 then
            --valid schema
       else
            --invalid
       end if;
    end

  • How do you put a command line in adobe illustrator?

    how do you put a command line in adobe illustrator?

    Your question makes no sense. What exactly are you trying to do?

  • How can I use srvctl command line for change "Failover type" and "F method"

    Hi all,
    I am using Oracle One Node (11.2.0.3), and I have a service:
    /u01/11.2.0/grid/bin/srvctl config service -d orcl
    Service name: orcldb
    Service is enabled
    Server pool: orcl
    Cardinality: 1
    Disconnect: false
    Service role: PRIMARY
    Management policy: AUTOMATIC
    DTP transaction: false
    AQ HA notifications: false
    Failover type: NONE
    Failover method: NONE
    TAF failover retries: 0
    TAF failover delay: 0
    Connection Load Balancing Goal: LONG
    Runtime Load Balancing Goal: NONE
    TAF policy specification: BASIC
    Edition:
    Preferred instances: orcl_1
    Available instances:
    I would like to change "Failover type" and "Failover method" to:
    Failover type: SELECT
    Failover method: BASIC
    How can I do that? Is there any graphical tool for it? Or, How can I use srvctl command line for change it?
    Thanks in advance.
    Leonardo.

    user10674190 wrote:
    Hi all,
    I am using Oracle One Node (11.2.0.3), and I have a service:
    /u01/11.2.0/grid/bin/srvctl config service -d orcl
    Service name: orcldb
    Service is enabled
    Server pool: orcl
    Cardinality: 1
    Disconnect: false
    Service role: PRIMARY
    Management policy: AUTOMATIC
    DTP transaction: false
    AQ HA notifications: false
    Failover type: NONE
    Failover method: NONE
    TAF failover retries: 0
    TAF failover delay: 0
    Connection Load Balancing Goal: LONG
    Runtime Load Balancing Goal: NONE
    TAF policy specification: BASIC
    Edition:
    Preferred instances: orcl_1
    Available instances:
    I would like to change "Failover type" and "Failover method" to:
    Failover type: SELECT
    Failover method: BASIC
    How can I do that? Is there any graphical tool for it? Or, How can I use srvctl command line for change it?
    Thanks in advance.
    Leonardo.srvctl modify service -d database_name -s orcldb -q TRUE -m BASIC -P BASIC -e SELECT -z 180 -w 5 -j LONG
    Also see
    11gR2(11.2) RAC TAF Configuration for Admin and Policy Managed Databases [ID 1312749.1]

  • How can I deploy by command line on AS 10.1.3?

    I have used oracle AS 10.1.3.
    I have created ear file from command line.
    But I don't know how i can deploy by command line?
    However i can deploy from Web manage.
    So, Please tell me How i can deploy by command line when i want?
    Thx

    Hello,
    In OracleAS 10g R3 (10.1.3.x) you can deploy by command line using the admin_client.jar utility, that is exposed also as Apache Ant tasks. In 10.1.3.x you can use the same tool to deploy in a single stand alone OC4J instance to a multi-nodees cluster managed by OPMN.
    Here the documentation about this utility:
    - Deployment Guide
    - Deploying with the admin_client.jar Utility
    -Deploying with the OC4J Ant Tasks
    Regards
    Tugdual Grall

  • How do I create a "command-line-interface" for a game?

    Hey people,
    For a game I need to make a DOS-like command-line-interface where the user has at least 3 options to answer with, does anyone know how to go about this?
    Hope someone here can help me out!
    Kind regards,
    Angela

    I'm not sure what part of this you are having difficulty with. Imagine for a moment that instead of asking for your end user to type something into a text-entry field and to monitor what they type (perhaps when the ENTER key is pressed), that instead you provide 3 buttons on your stage. Responding to a button press in this scenario is much the same as responding to typed user input - your movie does something based on user interaction. Going back to the user entered text scenario, a text or field sprite can detect the ENTER key being pressed and examine the string the user has entered, something like:
    on keyDown me
      if _key.keyCode = 36 then
        stopEvent
        sText = sprite(me.spriteNum).member.text
        case sText of
          "hack": -- do whatever you need to here
          "research":
          "wait":
          otherwise:
        end case
      else
        pass
      end if
    end

  • How do I process user command line arguments inside of the Sequence Editor?

    Using TestStand 4.0, how would I go about storing "extra" command line arguments processed from the /runentrypoint command in the Sequence Editor specifically?

    djdewitt -
    TestStand 4.2 does not have this feature; however, we do have an internal issue (#163169) to track this request. You can actually get the commandline passed to the TestStand Sequence Editor using the below psuedo code in a sequence; however, currently the TestStand Sequence Editor displays a prompt when it does not recognize a custom token on the command-line and there is no way to suppress this.
    Locals.AppMgrRef = RunState.Engine.GetInternalOption(InternalOption_ApplicationManager);
    Locals.CommandsRef = Locals.AppMgrRef.CommandLineArguments;
    Locals.CountNum = Locals.CommandRef.Count;
    For i=0 to Locals.CountNum - 1
        Locals.CommandString = Locals.CommandRef.Item(i);
    End
    One suggestion is to use a batch file to write the commands to a dedicated text file and then launch the sequence editor. You can then use a sequence in the sequence editor to read from the file.
    Lastly, I just tried something and I do not necessarily recommend this, but I noticed that the Sequence Editor does not prompt when using the /goto token, so if I use the below command-line, it seems that no prompt appears, the goto command does nothing, and the psuedo code accesses the command-line tokens: 
    "C:\PathToApp\SeqEdit.exe" /goto "location tokens that do nothing" /run MainSequence "C:\PathToSequenceFile\GetCommandLineArgs.seq"
    Keep in mind that NI does not necessarily support this but it does seem to work for now.
    Scott Richardson
    National Instruments

  • Problem in passing parameters in command line in desktop

    Hi,
    I am trying to generate reports from command line (Oracle Discoverer 4i Version 4.1.42.04.00) but I am facing problems when I try to pass date or numeric parameters. It seems to work with strings
    The following command is successful when i pass string as parameters
    C:\orant\DISCVR4\dis4usr.exe /connect reports/reports@orcl /opendb load_report_1 /batch /sheet 2 /parameter "P Date" "31-JUL-2006 Month End" /export xls c:\Temp\load_report_!
    But in the following commands the command line execution stops when a worksheet with parameters is encountered. Once then parameter is entered the command line is executed successfully. In these problem cases it seems like the /parameter option is not being recognized. I have tried to pass parameters with double quotes, single quotes, without any quotes.
    C:\orant\DISCVR4\dis4usr.exe /connect reports/reports@orcl /opendb "load report 2" /sheet 3 /parameter "Select P Day" "20-JUN-2006" /batch /export xls c:\Temp\load_Report_2
    C:\orant\DISCVR4\dis4usr.exe /connect reports/reports@orcl /opendb "load report 3" /batch /sheet 1 /parameter "Enter Date Using Format YYYYMMDD" 20060703 /export xls c:\Temp\load_report_3
    The only difference I can see is that I have not used double quotes in the command line that is successful in generating reports with parameters.
    Any inputs will be appreciated - we are stuck in our project due to this issue. Many thanks.
    Warm regards
    Sucharita

    Hi
    I work in the same team as the original poster.
    We tried by changing NLS_DATE_FORMAT for the oracle_home.
    Just to clarify our issue I am describing it one more time below -
    Using Disc desktop (4.1.42) we are trying to run the reports using command line interface. Any report that takes character input for the parameters ,is running fine in the batch mode without prompting.
    Any report that takes Date/Numeric input for the parameters, though in batch mode, is prompting for user to give the parameters.We tried with quotes as well.
    For Example -
    1. Character input : when we run this command supplying the input parameter values (which are characters), report runs fine without prompting for values.
    C:\orant\DISCVR4\dis4usr.exe /connect rep/rep@orals /opendb Schd_Report /batch /sheet 2 /parameter "Process Date" "31-JUL-2006 Month End" /export xls c:\audit_report_5
    2. Date Input -
    C:\orant\DISCVR4\dis4usr.exe /connect rep/rep@orals /opendb "DLS.Arrears Reports" /batch /sheet 1 /parameter "Please Enter Date Using Format YYYYMMDD" 20060703 /export xls c:\CA_arr
    When we submit this we get a window prompting for the input values. So his is the issue.
    Thanks
    Raman

  • How to pass Tables through program line.

    Hi All,
    I have requirment in smart forms.
    I need to execute smartforms in form itself. means no chance to run with driver program.
    So i created program line which where write our logic for internal table. My question is how to pass created internal table from program line. i need to display the internal table data using loop.
    Thanks,
    Subbu

    Hi,
    Try this :
    code
    REPORT report2.
    DATA: text TYPE c LENGTH 10,
    rspar_tab TYPE TABLE OF rsparams,
    rspar_line LIKE LINE OF rspar_tab,
    range_tab LIKE RANGE OF text,
    range_line LIKE LINE OF range_tab.
    rspar_line-selname = 'SELCRIT1'.
    rspar_line-kind = 'S'.
    rspar_line-sign = 'I'.
    rspar_line-option = 'EQ'.
    rspar_line-low = 'ABAP'.
    APPEND rspar_line TO rspar_tab.
    range_line-sign = 'E'.
    range_line-option = 'EQ'.
    range_line-low = 'H'.
    APPEND range_line TO range_tab.
    range_line-sign = 'E'.
    range_line-option = 'EQ'.
    range_line-low = 'K'.
    APPEND range_line TO range_tab.
    SUBMIT report1 USING SELECTION-SCREEN '1100'
    WITH SELECTION-TABLE rspar_tab
    WITH selcrit2 BETWEEN 'H' AND 'K'
    WITH selcrit2 IN range_tab
    AND RETURN.
    [/code]
    Reward points if found helpful.....
    Cheers,
    Chandra Sekhar.

  • How to use the telnet command line in Labview

    Hi, someone can help me, I need to use a Telnet session in Labview but without using the http protocol, in this application I can only access the Telnet session using command line, here is an example of how I can access:
    From my computer, click on Start, then Run and then type in CMD.
    In the command line enter “telnet 192.168.0.1 5454” (without the quote marks) to bring up a blank DOS screen with a blinking cursor.
    Type “AT” and press the ENTER key, you should receive an “OK” response.
    Type in capital letters “AT+CMAR=1234” (without the quote marks)

    I had a similar situation and here is what I did...
    In MAX (Measurement and Automation eXplorer)
    Select Devices and Interfaces
    Select VISA TCP/IP Resources
    Create a new resource
    Select Manual Entry of Raw Socket
    Enter the IP address and port (23 is the standard telnet port)
    Give it a name. (VISA Ailas)
    Now this "Device" will show up in the VISA drop down just like any other VISA device.
    Use the VISA read and write just like you were communicating through a com port.
    Since Telnet does not have a stop bit like serial, make sure you enable the termination character.
    On your VISA reads set the number of characters to a big number, then VISA will read until it gets the termination character.
    See my attached snippet of my Telnet read vi
    Message Edited by RTSLVU on 06-16-2010 01:49 PM
    Message Edited by RTSLVU on 06-16-2010 01:50 PM
    Attachments:
    telnet.png ‏40 KB
    max1.png ‏33 KB
    max2.png ‏31 KB

  • How to run report on command line with user parameter?

    Hi,
    How do I run oracle report on command line (batch) with pre-set User Parameter values ? e.g. :P_1 ='SYSDATE' , :P_2 = 'DEPT_NO'
    Thanks

    Hello,
    If you are using rwrun :
    rwrun report=myreport destype=file desname=c:\temp\myreport.pdf desformat=pdf P_1='SYSDATE' P_2='DEPT_NO' userid=scott/tiger@dbalias
    If you are using rwclient , just add server=<reports server name> :
    rwclient server=myrepsevrername report=+myreport+ destype=file desname=c:\temp\myreport.pdf desformat=pdf P_1='SYSDATE' P_2='DEPT_NO' userid=scott/tiger@dbalias
    Regards

  • How do I pause C command-line program?

    Hello. I'm writing a little command-line game app in C and I'm curious about how I can pause the program to wait for the user to hit return. I want the user to need to hit return (or having to hit any key would work too) to make the program continue, and I would like the key that was hit not to appear on the screen -- just a simple sort of "hit any key to continue" type thing. In C++ I think we used something like system("Pause") or something like that -- don't really remember, but any help here will be greatly appreciated. Thanks!

    Something like this will print a prompt, then wait for a keystroke:
    printf("Hit any key to continue> ");
    getchar();
    However in a console application, it's not so easy to prevent the user's keystrokes from being echoed. There are ways to turn the echo off for the keystroke then restore it, but those can depend on the environment. I'd need to know whether you're running your program in an Xcode console window, a Terminal window, or elsewhere. In short, don't go there unless it's quite important to you. The above prompt will show any chars that are keyed-in as text after the arrow, which is what a user would expect.
    Hope that helps!
    - Ray

  • HT1277 I want to set up my email composition with a default me@alumni.myschool.edu address that is different from my ISP.  How do I configure?  Command line OK with me.

    Hi everyone,
    I want to set up my email composition with a default [email protected] address in the "Reply-to" field that is different from my ISP.  How do I configure mail to set this default? 
    I have looked through the help and fail to see an option in the Preferences -> Compose window. 
    I am OK with UNIX Command line tasks if that is the only way to set this default.
    Basically I have an alumni email redirection service, which is an address that never changes, even if I change ISP.  That way all my friends can use it an never change.  However, they tend to use whatever ISP address is, not what I have asked them to use. 
    I want to force emails I send to default to my alumni address when my friends reply, not my ISP address.  I want control over this.

    Confused Once Again wrote:
    I want to set up my email composition with a default [email protected] address in the "Reply-to" field that is different from my ISP.  How do I configure mail to set this default? 
    Email preferences --> select Account --> Account Information tab --> Email address.
    The Email address setting supplies the "from" mail address in a sent email for that account.
    I  been doing this for years (well in Eudora but it works in Mail too) since my return address is a mail forwarding service.  That lets me switch ISP's and no one is ever the wiser.  I just change the forwarding service "pointer" to point to my new ISP.  But everyone else see sees the same "from" address as it's always been.

Maybe you are looking for