Register
It is currently Sat Apr 19, 2014 3:26 am

Remove a Parameter


All times are UTC - 6 hours


Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Mon Jun 15, 2009 11:21 am   

Joined: Mon Jun 15, 2009 10:38 am
Posts: 1
I'm trying to write a wrapper script that removes a command-line flag if it's set, performs an action, and then calls a program without that flag. Here's some psudo-code:
Code:
Did the user call the script with -flag?
Yes: Set FLAG = 1 and run binary_app with all the parameters given to this script.
No: Run binary_app with all the parameters given to this script.


Here's one way:
Code:
OPTS = "$@"
# now remove -flag from OPTS and run binary_app $OPTS


Now suppose my wrapper script is named wrapper_script.sh. If I run
Code:
wrapper_script.sh "path/to/file with spaces.txt" -flag

or
Code:
wrapper_script.sh path/to/file\ with\ spaces.txt -flag

then when the wrapper script runs binary_app $OPTS, the file name with spaces gets split up and binary_app sees the filename parts as different arguments.

Here are some of my requirements:
1) I don't know what arguments binary_app takes but the user does. binary_app may take more arguments in the future.
2) The user must be able to specify -flag to wrapper_script, wrapper_script must get rid of this flag before passing the rest of the arguments on to binary_app, and it must perform other actions when -flag is detected.
3) I cannot change binary_app.
4) Filename parameters to wrapper_script.sh with spaces in them must be supported.

I suppose I could loop through every paramter until I find -flag, delete it, recombine the parameters, and then pass them off to binary_app. It seems like there should be a more elegant way, though.

Thanks,

Peter


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP