Wednesday, 15 July 2015

linux - Setting an argument with bash -



linux - Setting an argument with bash -

i run simple bash command:

rpm -uvh --define "_transaction_color 3" mypackage.rpm

which works properly.

but i'm trying script bash file, , create more flexible:

#!/bin/bash install_cmd=rpm install_opt="-uvh --define '_transaction_color 3'" ${install_cmd} ${install_opt} mypackage.rpm

however, keeps generating error:

error: macro % has illegal name (%define)

the error coming how --define , quoted _transaction_color handled. i've tried variety of escaping, different phrasing, making install_opt array, handled ${install_opt[@]}.

so far, attempts have not worked. clearly, want extremely simple. i'm not sure how accomplish it.

how can bash handle --define argument properly?

the problem quotes not processed after variable substitution. looks you're trying define macro named '_transaction_color.

try:

eval "${install_cmd} ${install_opt} mypackage.rpm"

however, improve solution utilize array:

install_opt=(-uvh --define '_transaction_color 3')

then:

${install_cmd} "${install_opt[$@]}" mypackage.rpm

it's of import set ${install_opt[@]} within double quotes requoting.

linux bash unix

No comments:

Post a Comment