Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
It is a little ugly to list all fixed parameter as above, do we have better code to handle various paramters ?
Blow? What is that?
It isn't clear what you are talking about.
I believe that you will be required to parse the argument list, whatever you have in mind. Since command parameters are (generally) allowed to be entered in any order then you would have to check each given parameter against all of the possible parameters for whatever command you are wrapping.
I think you would need to provide more details before anyone could provide you with good information.
Sorry I should specify it as wrapper for script, instead of command.
I need to use it for a script we used. The script could have different parameters , and no order is required. It is possible that we can run the command with no parameters or 2 , 4, 6 parameters (like -s , -o , -p, etc).
Like :
copyPkg.sh -s /home/src -d /home/dest -o optionalPara
If the script doesn't specify teh paramter, it could use default value.
like
copyPkg.sh
Since the original script is created by other group, I don't want to change the original one, but rather to add a wrapper to add additional function, like logging, clean data etc. and the wrapper need to handle all existing parameters of original scripts.
wrapper.sh copyPkg.sh
or wrapper.sh copyPkg.sh -s /home/src -d /home/dst
The simple way like below could work to add the logging function, but may not be a best way.
>cat wrapper.sh
$1 $2 $3 $4 $5 $6 $7 | tee test.log
(assume it has 0 to 6 parameters)
I am wondering if there is a general way to handle the different number of parameters.
IIUC, your original script has a variable # (1-6) of arguments, how do you intend that the wrapper knows which are meant for it when there are less than 6? Or is the wrapper only ever going to get a single argument (the last)?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.