[英]Using Variable in Shell script as input for another command
#!/bin/bash
sudo docker-compose -f /home/administrator/compose/docker-compose.yml up --build -d
OUTPUT=$(docker ps | grep 'nginx_custom' | awk '{ print $1 }')
echo $OUTPUT
sudo docker $OUTPUT nginx -s reload
This the the ID that get´s printed correctly in the console.这是在控制台中正确打印的 ID。
6e3b3aa3fbc4
This command works fine.该命令工作正常。
docker exec 6e3b3aa3fbc4 nginx -s reload
However the variable seems not to get passed to the command here:但是,该变量似乎没有在这里传递给命令:
sudo docker $OUTPUT nginx -s reload
I am quite unfamiliar with the shell:(. How do I pass the variable to a command that is longer than just echo?我对 shell 很不熟悉:(。如何将变量传递给比 echo 更长的命令?
add set -x
to the script and see what happens: you can probably get rid of grep and incorporate it inside awk将set -x
添加到脚本中,看看会发生什么:您可能可以摆脱grep并将其合并到awk 中
#!/bin/bash
set -x
sudo docker-compose -f /home/administrator/compose/docker-compose.yml up --build -d
OUTPUT=$(docker ps | awk '/ngnix_custom/{ print $1 }')
echo $OUTPUT
sudo docker $OUTPUT nginx -s reload
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.