预先启动并在条件下添加双重标价

发布于 2025-01-18 14:35:20 字数 560 浏览 3 评论 0原文

在使用 makefile 和 bash shell 脚本时,我最终得到了一个变量,其中包含:

build_ext --b2-args=libtorrent-python-pic=on --b2-args=address-model=32

我需要在前面加上 --global-option= 并在正确的位置附加双引号,例如:

--global-option=build_ext --global-option=--b2-args="libtorrent-python-pic=on"  --global-option=--b2-args="address-model=32"

请注意 --b2-args= 各不相同,不能视为理所当然。

到目前为止,我在前置部分所做的是使用 bash 数组:

printf "\x2D\x2Dglobal-option=%s " "${myarray[@]}"

但我宁愿使用 sed 来代替。

Playing with makefile and bash shell scripting where I ended-up having a variable containing:

build_ext --b2-args=libtorrent-python-pic=on --b2-args=address-model=32

I need to prepend --global-option= and append double-quotes at the right place such as:

--global-option=build_ext --global-option=--b2-args="libtorrent-python-pic=on"  --global-option=--b2-args="address-model=32"

Note that --b2-args= varies and cannot be taken as granted.

So far what I did for the prepending is using a bash array:

printf "\x2D\x2Dglobal-option=%s " "${myarray[@]}"

But I'd rather have a one-liner using sed instead.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

土豪我们做朋友吧 2025-01-25 14:35:20

使用任何SED:

$ sed 's/=\([^ ]*\)/="\1"/g; s/[^ ]*/--global-option=&/g' file
--global-option=build_ext --global-option=--b2-args="libtorrent-python-pic=on" --global-option=--b2-args="address-model=32"

Using any sed:

$ sed 's/=\([^ ]*\)/="\1"/g; s/[^ ]*/--global-option=&/g' file
--global-option=build_ext --global-option=--b2-args="libtorrent-python-pic=on" --global-option=--b2-args="address-model=32"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文