Uploaded image for project: 'Data Management'
  1. Data Management
  2. DM-37347

Improve detection of shell flavour in loadLSST.sh

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: To Do
    • Resolution: Unresolved
    • Fix Version/s: None
    • Component/s: lsst, lsstsw
    • Labels:
      None
    • Team:
      Architecture

      Description

      Using env var $SHELL is fragile when used to determine the current shell. For example, a user with '/bin/sh' login shell sources loadLSST.sh within a bash subprocess and the env var $SHELL remains /bin/sh

      A more robust method:

      thisshell=$(ps -cp "$$" -o command="")
      

      lsst_distrib code here. Stackoverflow here.

      This was seen in a batch environment where spawning subprocesses is typical, as opposed to a user laptop environment. Our workaround was to override $SHELL.

        Attachments

          Activity

          Hide
          tjenness Tim Jenness added a comment -

          Kian-Tat Lim I just found this ticket that was filed before Christmas. Not sure if you want to look at it or Matthias Wittgen.

          Show
          tjenness Tim Jenness added a comment - Kian-Tat Lim I just found this ticket that was filed before Christmas. Not sure if you want to look at it or Matthias Wittgen .
          Hide
          tjenness Tim Jenness added a comment -

          On my Mac:

          $ ps -cp "$$" -o command=""
          -zsh
          

          Show
          tjenness Tim Jenness added a comment - On my Mac: $ ps -cp "$$" -o command="" -zsh
          Hide
          ktl Kian-Tat Lim added a comment -

          Filtering out that initial - in a shell-and-OS-independent way will need at least one more command in the pipeline. Annoying.

          Show
          ktl Kian-Tat Lim added a comment - Filtering out that initial - in a shell-and-OS-independent way will need at least one more command in the pipeline. Annoying.
          Hide
          p.love Peter Love added a comment -

          The leading hyphen indicates this is a login shell. You could deal with it in the if clauses.

          BASH_REGEX="^-?bash"
          ZSH_REGEX="^-?zsh"
          thisshell=$(ps -cp "$$" -o command="")
          if [[ $thisshell =~ $BASH_REGEX ]]; then
            SHELL=bash
          elif [[ $thisshell =~ $ZSH_REGEX ]]; then
            SHELL=zsh
          else
            SHELL=dash
          fi 
          

          Show
          p.love Peter Love added a comment - The leading hyphen indicates this is a login shell. You could deal with it in the if clauses . BASH_REGEX= "^-?bash" ZSH_REGEX= "^-?zsh" thisshell=$( ps - cp "$$" -o command = "" ) if [[ $thisshell =~ $BASH_REGEX ]]; then SHELL= bash elif [[ $thisshell =~ $ZSH_REGEX ]]; then SHELL=zsh else SHELL=dash fi
          Hide
          ktl Kian-Tat Lim added a comment -

          Well, if we're going to do a whole if/elif block, we could just test known official shell characteristics such as $BASH_VERSION, $ZSH_VERSION, or go to something like https://www.av8n.com/computer/shell-dialect-detect

          Show
          ktl Kian-Tat Lim added a comment - Well, if we're going to do a whole if/elif block, we could just test known official shell characteristics such as $BASH_VERSION , $ZSH_VERSION , or go to something like https://www.av8n.com/computer/shell-dialect-detect

            People

            Assignee:
            ktl Kian-Tat Lim
            Reporter:
            p.love Peter Love
            Watchers:
            Fabio Hernandez, Kian-Tat Lim, Peter Love, Tim Jenness, Zhaoyu Yang
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:

                Jenkins

                No builds found.