问题
我的奇点容器中的一个包中的一个配置脚本包含这个(对我来说)完全合理的 bash 来修剪/
路径的尾随;
if [ "${MY_DIR_PATH: -1}" = "/" ]; then
MY_DIR_PATH="${MY_DIR_PATH%?}"
fi
它在我的机器上本地运行良好,但是当从%post
奇异容器的部分运行时,它会以Bad substitution
. 出了什么问题,正确的解决方法是什么?
最小的工作示例
将下面的文本另存为badSubs.def
然后尝试;sudo singularity build badSubs.sif badSubs.def
.
BootStrap: docker
From: ubuntu:18.04
# what is done when the container is built
%post
# make print colour #
GREEN='\033[0;32m'
NOCOLOUR='\033[0m'
# start
#echo "${GREEN}~~~ Give the user permission and control ~~~ ${NOCOLOUR}"
#umask 000
echo "${GREEN}~~~ this should work fine! ~~~ ${NOCOLOUR}"
MYSCRIPT=$SINGULAITY_ROOTFS/confuzzel
touch $MYSCRIPT
chmod u+x $MYSCRIPT
echo '#! /bin/bash' >> $MYSCRIPT
echo 'PATHY="/what/a/path/"' >> $MYSCRIPT
echo 'if [ "${PATHY: -1}" = "/" ]; then ' >> $MYSCRIPT
echo ' echo yay!' >> $MYSCRIPT
echo ' PATHY="${PATHY%?}"' >> $MYSCRIPT
echo 'fi' >> $MYSCRIPT
echo 'echo $PATHY' >> $MYSCRIPT
cat $MYSCRIPT
./confuzzel
# metadata
%labels
Author ClumsyCat
Version v1.0
%help
to build me
> sudo singularity build badSubs.sif badSubs.def
to run me do
> singularity run badSubs.sif