'Setting an argument with bash [duplicate]
I frequently run a simple bash command:
rpm -Uvh --define "_transaction_color 3" myPackage.rpm
which works properly.
But now I'm trying to script it into a bash file, and make it more flexible:
#!/bin/bash
INSTALL_CMD=rpm
INSTALL_OPT="-Uvh --define '_transaction_color 3'"
${INSTALL_CMD} ${INSTALL_OPT} myPackage.rpm
However, this keeps generating the error:
error: Macro % has illegal name (%define)
The error is coming from how --define and the quoted _transaction_color is handled.
I've tried a variety of escaping, different phrasing, even making INSTALL_OPT an array, handled with ${INSTALL_OPT[@]}.
So far, my attempts have not worked.
Clearly, what I want is extremely simple. I'm just not sure how to accomplish it.
How can I get bash to handle my --define argument properly?
Solution 1:[1]
It might be a bash issue with word splitting on space:
Try:
#!/bin/bash
IFS=$'\n'
INSTALL_CMD=rpm
INSTALL_OPT='-Uvh'
INSTALL_OPT_DEFINE='--define _transaction_color 3'
${INSTALL_CMD} ${INSTALL_OPT} ${INSTALL_OPT_DEFINE} myPackage.rpm
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
