I've got a Shell script (intended for Linux/Mac/Cygwin users) that wraps an executable JAR.Before passing the arguments (long or short form) to the Java program, I need to pre-process one single option (i.e. a path whose directory has to be added to Java classpath and the filename that has to be passed to the Java program).getopt and getopts will complain if I don't specify ALL the options passed to the script. However, I want to specify only the one I need to pre-process (in its short and long form).What's the alternative?FYI, here is a rough illustration of what I want to do:#!/bin/sh# extracts _FOLDER_ and _FILE_ from --changelog/-c option# I need the add the _FOLDER_ to Java classpath# and _FILE_ to my programjava -cp .:_FOLDER_:my.jar my.main.class ALL_OTHER_OPTIONS
Pre-process 1 single option
shell
You have to parse all the options (the same way as the wrapped command does), or else you need to resort to heuristics and be prepared for it to fail in many cases.Assuming you're writing a:#! /bin/sh -# process optionsexec cmd $@And cmd accepts -a, -b, -c with argument and -n, -p without argument, and your wrapper wants to know what's the argument to -c.Then what is your wrapper to do if the script is called as:wrapper.sh -npc foowrapper.sh -b -c -n -ca-cwrapper.sh -- -cxIt can't find out what the argument to -c is unless it knows -n and -p don't take arguments and -a, -b do.You could use heuristics: look for an argument that starts with - and contains c and look at what's after that, but that would fail on all those examples above (except the first one as it happens -n and -p don't take arguments).