Problem
One of the configuration scripts from a package in my singularity container contains this perfectly reasonable (to me) bit of bash to trim a trailing /
off a path;
if [ "${MY_DIR_PATH: -1}" = "/" ]; then
MY_DIR_PATH="${MY_DIR_PATH%?}"
fi
It works fine natively on my machine, but when run from the %post
section of a singularity container it fails with Bad substitution
.
What's going wrong and what is the correct workaround?
Minimal working example
Save the text below as badSubs.def
then try; 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