用循环附加字符串到变量,将格式完好无损地保持在bash中
我现在对冲刺的要求感到震惊,无法破解它,并要求您帮助我有点复杂的要求。
- 我有一个循环,可以输出JSON文件列表。
in my_list中的i;做回声$ i;完成
根据环境,此列表可能在15至30之间变化。
$ i
输出看起来像这样“ Apple.json
,boy.json
”等。
- 我现在想要
的输出$ i
在下面的curl命令中,并在上保持“ action [] [file_path] = json_files/$ sync_env/$ i.json” \
和- -form“ action [] [content] =< $ i.json” \
。
请注意,没有文件可以附加,并且通过分配给变量,所有这些都是动态的 例如:my_ultimation_dynamic_command
${CURLPOST} --form "branch=default-branch" \
--form "commit_message=[ Syncing ]" \
--form "actions[][action]=update" \
--form "actions[][file_path]=JSON_FILES/$SYNC_ENV/$i.json" \
--form "actions[][content]=<$i.json" \
-H "PRIVATE-TOKEN:$TOKEN" "https://gitlab.myorg.com/api/v4/projects/$prid/repository/commits"
- 如下...
${CURLPOST} --form "branch=default-branch" \
--form "commit_message=[ Syncing ]" \
--form "actions[][action]=update" \
--form "actions[][file_path]=JSON_FILES/$SYNC_ENV/apple.json" \
--form "actions[][content]=<apple.json" \
--form "actions[][action]=update" \
--form "actions[][file_path]=JSON_FILES/$SYNC_ENV/boy.json" \
--form "actions[][content]=<boy.json" \
...and so on until $i is empty
-H "PRIVATE-TOKEN:$TOKEN" "https://gitlab.myorg.com/api/v4/projects/$prid/repository/commits"
- 循环结束后的预期输出和
$ my_ultimate_dynamic_command /代码>
如果有人可以帮助我,请感谢它。
I am struck with the requirements for a sprint now and unable to crack it and request you to help me with a bit complex requirement.
- I have a loop that outputs a list of JSON files.
for i in my_list; do echo $i; done
This list may vary between 15 and 30 based on the environment.
the $i
output looks something like this "apple.json
, boy.json
", etc.
- I now want the output of
$i
in the below curl command and keep on append to--form "actions[][file_path]=JSON_FILES/$SYNC_ENV/$i.json" \
and--form "actions[][content]=<$i.json" \
.
Kindly note there are no files to append and all this is dynamic by assigning to a variable
eg: my_ultimate_dynamic_command
${CURLPOST} --form "branch=default-branch" \
--form "commit_message=[ Syncing ]" \
--form "actions[][action]=update" \
--form "actions[][file_path]=JSON_FILES/$SYNC_ENV/$i.json" \
--form "actions[][content]=<$i.json" \
-H "PRIVATE-TOKEN:$TOKEN" "https://gitlab.myorg.com/api/v4/projects/$prid/repository/commits"
- expected output after the loop ends and echo of
$my_ultimate_dynamic_command
as below...
${CURLPOST} --form "branch=default-branch" \
--form "commit_message=[ Syncing ]" \
--form "actions[][action]=update" \
--form "actions[][file_path]=JSON_FILES/$SYNC_ENV/apple.json" \
--form "actions[][content]=<apple.json" \
--form "actions[][action]=update" \
--form "actions[][file_path]=JSON_FILES/$SYNC_ENV/boy.json" \
--form "actions[][content]=<boy.json" \
...and so on until $i is empty
-H "PRIVATE-TOKEN:$TOKEN" "https://gitlab.myorg.com/api/v4/projects/$prid/repository/commits"
- Finally, the dynamically generated variable should be executed as
eval $my_ultimate_dynamic_command
Appreciate it if someone could help me with this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试一下
Try this