Gra*_*ell 4 bash shell-script docker
像许多 bash 问题一样,我 100% 肯定有答案,但在谷歌上搜索它们是具有挑战性的。
我试图理解以下脚本:
#!/bin/bash
# available options
export OPX_GIT_TAG="${OPX_GIT_TAG:-no}"
# package distribution
export OPX_RELEASE="${OPX_RELEASE:-unstable}"
# currently tracked release
export DIST="${DIST:-stretch}"
export ARCH="${ARCH:-amd64}"
export CUSTOM_SOURCES="${CUSTOM_SOURCES:-}"
# docker image name
IMAGE="opxhub/build"
# docker image tag
VERSION="${VERSION:-latest}"
interactive="-i"
if [ -t 1 ]; then
# STDOUT is attached to TTY
interactive="-it"
fi
read -d '' opx_docker_command <<- EOF
docker run
--rm
--name ${USER}_$(basename $PWD)_$$
--privileged
-e LOCAL_UID=$(id -u ${USER})
-e LOCAL_GID=$(id -g ${USER})
-v ${PWD}:/mnt
-v $HOME/.gitconfig:/home/opx/.gitconfig
-v /etc/localtime:/etc/localtime:ro
-e ARCH
-e DIST
-e OPX_RELEASE
-e OPX_GIT_TAG
-e CUSTOM_SOURCES
${interactive}
${IMAGE}:${VERSION}
EOF
if [[ $# -gt 0 ]]; then
# run command directly
# not using bash because tar fails to complete
# root cause unknown (see opx_rel_pkgasm.py:tar_in)
$opx_docker_command sh -l -c "$*"
else
# launch interactive shell
# using bash here because tar does not fail in an interactive shell
$opx_docker_command bash -l
fi
Run Code Online (Sandbox Code Playgroud)
我被它们是如何产生的困惑docker-run
有关部件-命令ARCH
,DIST
,OPX_RELEASE
特别是-等。那些不应该用${}
? 如果不是,这些变量是如何传递的?
归档时间: |
|
查看次数: |
50 次 |
最近记录: |