shell - shell中字符串中的字符串
问题描述
下面是我的代码示例
command mycommand /path/location arg1="my valu1" arg2="my value2"
当我通过对参数值进行硬编码来执行此命令时,它会起作用。
但是当我使用以下代码格式时:
for i in "$@" do
str+="$i "
done
command mycommand /path/location $str
where $str="arg1="my valu1" arg2="my value2""
它不接受“my value1”作为单个字符串。它将“my”作为一个字符串,将“value2”作为一个单独的字符串。
现在如果我使用
command mycommand /path/location "$str"
然后 $str="arg1="my valu1" arg2="my value2"" 作为一个完整的字符串。但我希望命令应该通过程序方式以以下格式执行。
command mycommand /path/location arg1="my valu1" arg2="my value2"
这个怎么做?
解决方案
Don't try to append your arguments into a string just pass along "$@"
to your actual command inside the script:
command mycommand /path/location "$@"
推荐阅读
- google-cloud-speech - c# google Speech to text api 结果质量不好
- swift - Swift:解析服务器登录 facebook 无法检索邮件
- kotlin - 等效于 Java 的“公共静态最终字符串”
- c# - 基于属性的 LINQ 相交
- ios - 无法使用 Google Map SDK iOS 绘制 GMSPolyline
- java - Matlab中YARP的使用方法
- android - 将firebase添加到项目后同步失败
- mysql - 如何利用join做一个简单的报表
- ruby - Watir运行错误
- python - Why use class method over a regular function in python