gpt4 book ai didi

Bash:将长字符串参数拆分为多行?

转载 作者:行者123 更新时间:2023-11-29 08:44:03 25 4
gpt4 key购买 nike

给定一个带有单个长字符串参数的命令,例如:

mycommand -arg1 "very long string which does not fit on the screen"

是否有可能以某种方式拆分它,类似于如何使用 \ 拆分单独的参数。

我试过:

mycommand -arg1 "very \
long \
string \
which ..."

但这行不通。

mycommand 是一个外部命令,因此不能修改为采用单个参数。

最佳答案

您可以将字符串分配给这样的变量:

long_arg="my very long string\
which does not fit\
on the screen"

然后只需使用变量:

mycommand "$long_arg"

在双引号内,移除以反斜杠开头的换行符。请注意,字符串中的所有其他空格都很重要,即它将出现在变量中。

关于Bash:将长字符串参数拆分为多行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46807924/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com