Coder Social home page Coder Social logo

Comments (2)

toffentoffen avatar toffentoffen commented on May 25, 2024

I think I've found the reason why it is failing, and it's failing on macOSX BigSur bash (GNU bash, version 3.2.57(1)-release (arm64-apple-darwin20)). MacOsX Bigsur is shipped with a really old version.
It seems that enabling errexit

set -e

is making the script exit when if ! command grep -qc 'GETMESH_HOME' "$detected_profile"; then is executed . Even though it is a tested command (inside an if). A tested command, as per gnu bash documentation, is:

The shell does not exit if the command that fails is part of the command list immediately following a while or until keyword, part of the test in an if statement, part of any command executed in a && or || list except the command following the final && or ||

Extensive information about set -e can be found at http://mywiki.wooledge.org/BashFAQ/105
which includes as well a reference to how subshells have propagated that flag https://www.in-ulm.de/~mascheck/various/set-e/

Possible Solutions

  • Use set +e before the problematic if statement: I would discard that option because we will need to remember to set it back, and if the code branching changes over time it can be difficult to maintain it.

  • Subshells. Seems like subshell does the trick because set -e is not propagated (maybe even by mistake). We can either:

    • extracting out the grep command and storing the count into a local variable:
      local getmesh_home_count=$(command grep -c 'GETMESH_HOME' "$detected_profile")
      if [[ "$getmesh_home_count" -eq 0 ]];
    
    • wrap the if command in parenthesis: if ! (command grep -qc 'GETMESH_HOME' "$detected_profile"); then
  • Remove set -e from the script as it seems problematic. I would suggest avoid that approach as it will make us to implement error handling manually at each command. Although it might be the best, I don't think it is worth the effort as this problem might only happen in concrete bash versions.

I will go ahead and create a PR for using the wrap if statement approach.

from getmesh.

mathetake avatar mathetake commented on May 25, 2024

thanks so much @toffentoffen for the thorough investigation!

I will go ahead and create a PR for using the wrap if statement approach.

agreed, thank you! 😄

from getmesh.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.