Skip to content
Advertisement

Can substring expansion be used in dash shell or bourne shell?

I’m converting an app to a new image, and the existing commands use substring expansion to set the artifact version like so: mvn clean versions:set -DnewVersion="0.1.$VCSINFO.I${INFO:0:6}.M$OTHER_INFO". I’m using a ubuntu image that defaults to /bin/sh, and I am unable to figure out how to either do something equivalent in bourne shell, or switch shells to run the command. I know bash is installed because I can see it in /etc/shells.

I tried using RUN ['/bin/bash', '-c', '...'] but I can see it is just running that command like so The command '/bin/sh -c ['/bin/bash', '-c',.... What is the best way to convert this functionality over to this new image?

Advertisement

Answer

You can run a bash command in two ways, even from sh: Either by passing the string ‘/bin/bash path/to/your/cmd’ to the -c option of sh, or by setting the x-bit in cmd and having as the first line in cmd a #!/bin/bash.

Hence in your setting I would try either a RUN ['/bin/bash /path/to/your/cmd'] or just do a RUN ['/path/to/your/cmd'] and ensure that cmd has the #! line mentioned above, or complicated but fail safe – write a sh wrapper script, which then invokes the bash script in turn. Hence, if this wrappe script is called /path/to/your/cmdwrapper.sh, its content would be

:
/bin/bash /path/to/your/cmd
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement