Skip to content

Singularity shell script must be POSIX compliant since exec'ed in /bin/sh

On OSG, jobs produce these errors:

/.singularity.d/actions/exec: 22: /etc/eic-env.sh: [[: not found
/.singularity.d/actions/exec: 24: /etc/eic-env.sh: [[: not found
/.singularity.d/actions/exec: 26: /etc/eic-env.sh: [[: not found

caused by bashisms in eic-env.sh

    if [[ $version =~ 'unstable' ]]; then
      sigil="?"
    elif [[ $version =~ 'nightly' ]]; then
      sigil=""
    elif [[ $version =~ 'testing' ]]; then
      sigil="*"
    else # stable
      sigil="+"
    fi

We probably should make eic-env.sh explicitly a sh script, not a bash script, including with the shebang line at the top.

Maybe we need to add a shellchecker and put that in CI.

shellcheck --shell=sh eic-env.sh (for 1d27166c):

In eic-env.sh line 4:
  if [ -r $i ]; then
          ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
  if [ -r "$i" ]; then


In eic-env.sh line 5:
    . $i
      ^-- SC1090: Can't follow non-constant source. Use a directive to specify location.
      ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
    . "$i"


In eic-env.sh line 21:
  if [ ! -z ${container} ]; then
       ^-- SC2236: Use -n instead of ! -z.
            ^----------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
  if [ ! -z "${container}" ]; then


In eic-env.sh line 22:
    if [[ $version =~ 'unstable' ]]; then
       ^--------------------------^ SC2039: In POSIX sh, [[ ]] is undefined.


In eic-env.sh line 24:
    elif [[ $version =~ 'nightly' ]]; then
         ^-------------------------^ SC2039: In POSIX sh, [[ ]] is undefined.


In eic-env.sh line 26:
    elif [[ $version =~ 'testing' ]]; then
         ^-------------------------^ SC2039: In POSIX sh, [[ ]] is undefined.


In eic-env.sh line 45:
  /bin/ls --color=auto $@
                       ^-- SC2068: Double quote array expansions to avoid re-splitting elements.


In eic-env.sh line 48:
  /usr/bin/less -R $@
                   ^-- SC2068: Double quote array expansions to avoid re-splitting elements.


In eic-env.sh line 51:
  /bin/grep --color=auto $@
                         ^-- SC2068: Double quote array expansions to avoid re-splitting elements.


In eic-env.sh line 59:
  export -f ls
         ^-- SC2039: In POSIX sh, export -f is undefined.


In eic-env.sh line 60:
  export -f less
         ^-- SC2039: In POSIX sh, export -f is undefined.


In eic-env.sh line 61:
  export -f grep
         ^-- SC2039: In POSIX sh, export -f is undefined.

For more information:
  https://www.shellcheck.net/wiki/SC2068 -- Double quote array expansions to ...
  https://www.shellcheck.net/wiki/SC1090 -- Can't follow non-constant source....
  https://www.shellcheck.net/wiki/SC2039 -- In POSIX sh, [[ ]] is undefined.