设置使用bash参数 [英] Setting an argument with bash

查看:200
本文介绍了设置使用bash参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常运行一个简单的bash命令:

I frequently run a simple bash command:

rpm -Uvh --define "_transaction_color 3" myPackage.rpm

这正常工作。

但现在我试图脚本它变成一个bash文件,并使其更加灵活:

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)

该错误是来自如何 - 定义和引用 _transaction_color 的处理结果
我已经尝试了各种逃避,不同的措辞,甚至使得 INSTALL_OPT 的数组, $ {处理INSTALL_OPT [@]}

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.

怎样才能得到的bash来处理我的 - 正确地定义参数

How can I get bash to handle my --define argument properly?

推荐答案

的问题是,引号不变量代换后处理。所以它看起来像你试图定义一个名为宏'_ transaction_color

The problem is that quotes are not processed after variable substitution. So it looks like you're trying to define a macro named '_transaction_color.

请尝试使用数组:

INSTALL_OPT=(-Uvh --define '_transaction_color 3')

然后

"$INSTALL_CMD" "${INSTALL_OPT[@]}" myPackage.rpm

将是很重要的 $ {INSTALL_OPT [@]} 双引号内得到requoting。

It's important to put ${INSTALL_OPT[@]} inside double quotes to get the requoting.

这篇关于设置使用bash参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆