Why You Should Put Braces around Your Variables When Shell Scripting

แชร์
ฝัง
  • เผยแพร่เมื่อ 17 ธ.ค. 2024

ความคิดเห็น • 13

  • @mikemccartneyable
    @mikemccartneyable 3 หลายเดือนก่อน +1

    Superb video ... using {} on ALL variables and suddenly my coding efforts work a lot more often 👍

  • @N.A._McBee
    @N.A._McBee 2 ปีที่แล้ว +3

    Really helpful and thoroughly explained! Thanks, mate!

  • @aoxomoxoa625
    @aoxomoxoa625 2 ปีที่แล้ว +1

    I really like the way you present information!

  • @nnutipa
    @nnutipa 3 ปีที่แล้ว +2

    Just excellent! I have nothing to add, all cases are here.

    • @NickJanetakis
      @NickJanetakis  3 ปีที่แล้ว +1

      Thanks. I'm sure there's other more obscure Bash features that require braces too, but in my day to day the ones I included are what I tend to hit.

    • @nnutipa
      @nnutipa 3 ปีที่แล้ว

      @@NickJanetakis it is also worth mentioning why it's always a good idea to put bash variables in qoutes

    • @NickJanetakis
      @NickJanetakis  3 ปีที่แล้ว +1

      @@nnutipa Yep, check the blog post at the start of the video (in the description).

  • @fuseteam
    @fuseteam 3 ปีที่แล้ว +1

    cool this explains a lot, i didn't know you could do all that with bash variables xD

  • @hhskladby1596
    @hhskladby1596 3 ปีที่แล้ว

    You may use shellcheck with correct shebang to learn what holds for your shell. Some things here depend on using a recent version of Bash / zsh and are not portable shell scripting. This is not saying "all wrong!", but just do not believe in silver bullets.

  • @fuseteam
    @fuseteam 3 ปีที่แล้ว

    starts off with "why you should always quote your variable"
    proceeds to not quote a single variable
    yes i know twas the focus was on showcases the usefulness of braces, the quotes would've gotten in the way xD

    • @NickJanetakis
      @NickJanetakis  3 ปีที่แล้ว +2

      Plot twist: Inside of a heredoc you don't need to quote variables because they're effectively quoted by the heredoc.
      Try it out. Quoting them literally outputs the quotes around the variable.

    • @fuseteam
      @fuseteam 3 ปีที่แล้ว +1

      @@NickJanetakis haha sneaky! that's quite an interesting feature