Set shell in runscript?

685 views
Skip to first unread message

Martin Cuma

unread,
Sep 20, 2017, 7:10:16 PM9/20/17
to singularity
I don't seem to be able to set a shell in runscript. It seems to insist on using /bin/sh.

E.g. if I bootstrap as:
BootStrap: docker
From: ubuntu:16.10
%runscript
  #!/bin/tcsh
  setenv FOO bar

$ sudo singularity create ubuntu_python.img
$ sudo singularity bootstrap ubuntu_python.img
$ ./ubuntu_python.img
/.singularity.d/runscript: 4: /.singularity.d/runscript: setenv: not found

$ singularity shell ubuntu_python.img

$ cat /.singularity.d/runscript
#!/bin/sh

#!/bin/tcsh
setenv FOO bar

So, /bin/sh seems to be hard coded in /.singularity.d/runscript.

Is there a way to change that?

Thanks,
MC

PS: Thanks for the quick fix of the Docker bootstrap problems and detailed explanation.

vanessa s

unread,
Sep 20, 2017, 7:16:49 PM9/20/17
to singu...@lbl.gov
Hey Martin,

setenv I don't think is a command you would find in ubuntu, I believe it's csh (cshell). I think you would want to export the variable instead, eg:

SHELL=/bin/bash
export SHELL

however in this case, Singularity has a more flexible way of specifying the shell (let's say that a future user of the container doesn't want a hard coded shell!) you can specify the shell with --shell or with SINGULARITY_SHELL, eg:

singularity shell --shell /bin/bash container.img
SINGULARITY_SHELL=/bin/bash singularity shell container.img

and note that if you are using a (much) older image, you would just do:

SHELL=/bin/bash singularity shell container.img

Give those a try and see if you can get the functionality you want!

Best,

Vanessa

--
You received this message because you are subscribed to the Google Groups "singularity" group.
To unsubscribe from this group and stop receiving emails from it, send an email to singularity+unsubscribe@lbl.gov.



--
Vanessa Villamia Sochat
Stanford University '16

Martin Cuma

unread,
Sep 21, 2017, 5:14:55 PM9/21/17
to singularity
Hi Vanessa,

thanks for the quick reply. The example showed the tcsh syntax in runscript on purpose to show that AFAIK there's no way to force other shell than /bin/sh to interpret the %runscript section.

Though now I am not sure if there's a major need to change that since I can do something like
sudo singularity exec -w sed -i -e 's/bin\/sh/bin\/bash/g' /.singularity.d/runscript
to change the runscript shell interpreter to whatever I want.

And, I figured out the source of the question - using shell function in /bin/sh vs. bash.

I used one of the possible bash syntaxes, i.e.
function myfn()
{
something
}

which the /bin/sh did not like. Changing this to:
myfn()
{
something
}

Fixed that problem.

Thanks,
MC
Reply all
Reply to author
Forward
0 new messages