Coder Social home page Coder Social logo

Comments (2)

progrium avatar progrium commented on August 30, 2024

Mmmm, it kind of goes both ways. I like the simplicity of not using -n because for people that forget all the operators it's actually more readable. Esp if they know they can not use -n for the same thing they'll wonder "why is -n being used? what does it mean again?"

On top of that, I'm trying to focus on Bash and double-brace tests. So if your plan is to be portable to non-Bash shells, this is important, but not what my guide is optimizing for.

from bashstyle.

stuartpb avatar stuartpb commented on August 30, 2024

There's [[ ! -z "whatever" ]] if you're trying to be minimal with operators.

I think that, on the scale of "making people remember hard things", [[ ! -z is the best way to represent "string not null", but [[ -n is less of a burden to comprehend than [[ "$string" ]]. -n involves remembering one more test flag (which, when not clear from context/comments, are always one quick Google search away): [[ "$variable" ]] requires understanding that, unlike commands (including the single-brace [ test), expanding the first argument to [[ is not equivalent to substituting the content of the string, and double-brace has this whole special syntax that applies to how it evaluates arguments that doesn't apply for anything else.

And, to go back to my initial point, a forgotten operand is easier to type by accident.

from bashstyle.

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.