【发布时间】:2020-05-23 11:47:13
【问题描述】:
下面的代码是一个shell脚本find.sh。我在我的应用程序中包含指令,告诉用户从它所在的默认目录运行此脚本,因为它的目的是查看父目录并查看 Dockerfile 是否存在。
#!/bin/bash
FILE=../Dockerfile
if [ -f "$FILE" ]; then
# Change to the parent directory.
cd ..
fi
# Try stop a Docker container. This code could be anything.
docker container stop container_name
但是,这有其局限性,因为它强制用户从自己的目录运行脚本,否则 cd .. 不会将目录更改为 Dockerfile 的预期位置。
如何修改此脚本,以便用户可以从任何目录运行它,并且它仍然可以找到并更改到 Dockerfile 目录?
【问题讨论】:
-
检查 linux
find命令。 tecmint.com/35-practical-examples-of-linux-find-command -
如果这是您的整个脚本,您可以从任何地方运行
docker stop命令;它不依赖于在特定目录中,也不需要 Dockerfile 存在。
标签: linux bash shell docker ubuntu