-1

I want to execute a command in various images. I use a simple for bash loop.

for i in `ls *.sif`
do
   singularity exec $i cat /etc/os-release
done

I expect the script to print the os-release information for ALL images in that directory. Instead, it prints the information of the first one and it returns the prompt. If I run fg command the command in the next image is executed, and so on. For n image, I have to run fg command n-1 times.

Interestingly, if I replace the command with timeout 10 singularity exec $i cat /etc/os-release, it would continue but it won't run the command inside the container.

Amin
  • 251
  • 2
  • 15
  • 3
    What is `ls` doing in there? It should just be `for i in *.sif`. – Barmar May 09 '19 at 05:28
  • 2
    See [why not parse ls?](https://unix.stackexchange.com/questions/128985/why-not-parse-ls) – Barmar May 09 '19 at 05:32
  • Put `set -x` at the beginning of the script to see the commands that are being executed. – Barmar May 09 '19 at 05:34
  • @Barmar I think `exec` exits the shell after its first execution - https://www.computerhope.com/jargon/e/exec.htm – R4444 May 09 '19 at 05:42
  • 1
    @Ruturaj That's the `bash` `exec` command, this is the `exec` option to the `singularity` command. – Barmar May 09 '19 at 05:44
  • 1
    @Ruturaj See https://www.sylabs.io/guides/3.2/user-guide/cli/singularity_exec.html – Barmar May 09 '19 at 05:45
  • @Barmar interestingly, if I replace the command with `timeout 2 singularity exec $i cat /etc/os-release`, it would continue, but it won't run the command inside the container. – Amin May 09 '19 at 05:50

1 Answers1

0

it just works as expected for me (singularity 3.2.0 on CentOS-7), can you re-try with a clean ~/.bashrc file? or with an empty binded $HOME? or with --no-home flag

H=`mktemp -d`
for i in *.sif; do
echo "$i"
singularity exec -H "$H" "$i" cat /etc/os-release
done

if with these 3 options your exec works fine, you need to fix your .bashrc file.

Tru Huynh
  • 1
  • 1