我是 Linux 新手,我需要帮助来编写如下脚本。
运行命令以获取输出,即 ID#,
docker exec -it scalelite-api bin/rake servers:add[https://bbb1.test.com/bigbluebutton/api,XYZ1234]
这将返回 ID#
然后我想将输出 ID# 插入到脚本的另一行中。
docker exec -it scalelite-api bin/rake servers:enable[ID#]
答案1
假设 XYZ1234 不是实值:
#!/bin/bash
# myscript.sh
# ${1} denotes the first argument of the shell script
export ID=$(docker exec -it scalelite-api bin/rake "servers:add[https://bbb1.test.com/bigbluebutton/api,${1}]")
# Puts the value of the command output into environment variable "ID"
echo "$ID"
# Outputs the value of environment variable ID
$ chmod +x myscript.sh
$ ./myscript.sh "XYZ1234"
当然,你可以稍后添加检查 docker 命令是否失败等。