I'm writing a wrapper script for that uses getopts to set various options for mysqldump. It's working well so far.
However one thing I would like to do is be able to add another option in my shell script, the contents of which should be passed to the mysqldump command exactly. Sort of like an options pass through like this:
./mysqldumpwrapper.sh -u username -p password -h localhost -o "--no-create-db --replace"
with the string content of the -o argument passed exactly through to my mysqldump command.
Because I'm using getopts when trying the above I get the following output:
Invalid option: --
Does anyone know how to work around this?
Is there a way to escape the entry of options so that getopts won't parse the contents as another option?
Then when it comes to triggering the actual command from my shell script, this is what I've got:
mysqldump "$OPTIONSPASSTHROUGH" --host=$MYSQL_HOST --user=$MYSQL_USER --password=$MYSQL_PASS "$DB" > "$FILE_DEST"
Because there may well be spaces in the OPTIONSPASSTHROUGH variable, I have quoted that variable in that command. Is that correct?
ooption is defined to accept an argument (with a:following it in the option specification), the above should work. Can you post the excerpt of your code that is giving you trouble?ooption did not have a:in the optspec. Adding the:and it worked straight away! Add that as an answer and I'll accept it.no-create-db replaceand prefix with--before pass tomysqldump.