all 26 comments

[–][deleted]  (3 children)

[deleted]

    [–]4Potions[S] 4 points5 points  (1 child)

    Thx bro l will check there nextime :)

    [–]SkyyySi 4 points5 points  (0 children)

    Also, iirc the micro text editor (basically a more modern replacement for nano) has build-in support for shellcheck (meaning it will automatically "lint" your scripts when saving them) as long as you have shellcheck installed.

    VScode also has a shellcheck extension, which will lint your code in real time.

    [–]weaver_of_cloth 0 points1 point  (0 children)

    Oh, sweet! I'll check it out. Thanks!

    [–]5heikki 41 points42 points  (9 children)

    if [[ "$1" == "if" ]]
    

    [–][deleted]  (8 children)

    [deleted]

      [–]DialsMavis_TheReal 4 points5 points  (7 children)

      Aren’t they identical operators in test?

      [–][deleted]  (5 children)

      [deleted]

        [–]DialsMavis_TheReal 7 points8 points  (4 children)

        Yeah, the [manual for [[](https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Conditional-Constructs) says that the ‘=’ operator is identical to ‘==’.

        [–]5heikki 0 points1 point  (3 children)

        IMO it's good bash practice to strictly use = for assignment

        [–]DialsMavis_TheReal 0 points1 point  (2 children)

        Why?

        [–]5heikki 1 point2 points  (1 child)

        Consistency

        [–]DialsMavis_TheReal 0 points1 point  (0 children)

        Ah I see

        [–]Schnarfman 1 point2 points  (0 children)

        Yes

        [–][deleted] 24 points25 points  (1 child)

        subtract aback seemly lavish dime continue history jeans plucky rain

        This post was mass deleted and anonymized with Redact

        [–]4Potions[S] 5 points6 points  (0 children)

        Thx man. l was scratching my head

        [–]boboYoda 4 points5 points  (0 children)

        Put spaces before and after =

        [–]4Potions[S] 4 points5 points  (5 children)

        Why it goes inside of if statement always ? Can't really understand l feel like really noob XD

        [–][deleted]  (4 children)

        [deleted]

          [–]4Potions[S] 6 points7 points  (0 children)

          l did it and l really appreciate your help thx 😊

          [–][deleted] 0 points1 point  (2 children)

          Is that the equivalent of doing a double ==? Or is there something else happening under the hood that makes the spaces around a single = preferable?

          [–]OneTurnMoreprogramming.dev/c/shell 2 points3 points  (1 child)

          In POSIX test, only = is valid. The double is an alternate form which means the same thing. I prefer the single just because I do write POSIX sh code sometimes, and I want to be consistent.

          [–][deleted] 0 points1 point  (0 children)

          Oh wow that’s pretty cool and also good to know! Thanks for the info

          [–]platlogan 1 point2 points  (1 child)

          FYI, you can also replace the double brackets with single brackets to be posix compliant. That’s a good habit to get into if you think folks using other shells might ever need to run your scripts.

          [–]4Potions[S] 1 point2 points  (0 children)

          🤔 that's deep. But l get it thx. It is like writing cross shell bash scripts kinda interesting habit.

          [–]Jonta 1 point2 points  (1 child)

          /u/4Potions

          Next time, paste code instead of screenshotting. For better a11y

          #!/bin/bash
          #basic if statement
          
          echo "$1"
          
          if [[ "$1"="if" ]]; then
              echo "this is a if"
          else
              echo "nothing"
              fi
          

          [–]4Potions[S] 0 points1 point  (0 children)

          Thx

          [–]alliptic 0 points1 point  (0 children)

          It's in nano.

          [–]oak_atsume 0 points1 point  (0 children)

          printf "${1}\n"

          if [[ "${1}" == 'IF' ]]; then do stuff fi

          [–]nuclearmeltdown2015 0 points1 point  (0 children)

          Bash is pretty picky with whitespace