POSIX Shell Has This Awesome Thing Called An Until Loop

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ก.ย. 2024
  • ==========Amazon Links==========
    ► Buy Anything: amzn.to/3d5gykF
    ► Blue Yeti USB Microphone: amzn.to/2X4pQHR
    ► Logitech C920 Pro Webcam: amzn.to/2THlJzE
    ► Neewer 176 LED Video Light: amzn.to/3eqp7a2
    💖 Subscribe and ding the bell for more videos!
    👍 Leave a like if you got something out of this video!
    ✍ Comment some video feedback or what you want to see next time!
    Sometimes when you're writing a shell script you want some sort of action to keep attempting to run until it works and that's when a really cool POSIX compliant loop structure called an until loop comes into play.
    ==========Support The Channel==========
    ► Patreon: / brodierobertson
    ► Paypal: www.paypal.me/...
    ► BTC Wallet Address: 1Aokiv3pFQXUEmh2LbzZQAwxMvq6bpT2UN
    ► ETH Wallet Address: 0x80451867c86bdf08c3888d407c1e3fcb6add61ed
    ► LBC Wallet Address: bLRN9fm17sCexKfgbYqmMj5xskZF2ogpEh
    =========Video Platforms==========
    📚 LBRY Podcast: open.lbry.com/...
    🎥 TH-cam Podcast: / @techovertea
    🎥 LBRY: open.lbry.com/...
    📚 LBRY Referral Link: lbry.tv/$/invi...
    📺 BitTube: bittube.tv/pro...
    ==========Social Media==========
    🎤 Discord: / discord
    🐦 Twitter: / brodieonyoutube
    🌐 Mastodon: mstdn.social/@...
    📷 Instagram: / techovertea
    🧠 Minds: www.minds.com/...
    ✉️ Telegram: t.me/BrodieRob...
    ==========Resources==========
    ==========My Repos==========
    🖥️ GitHub: github.com/Bro...
    ==========Credits==========
    🎨 Channel Art:
    All my art has was created by Supercozman
    / supercozman
    / supercozman_draws
    🎵 Ending music
    Music from filmmusic.io
    "Basic Implosion" by Kevin MacLeod (incompetech.com)
    License: CC BY (creativecommons...)
    DISCLOSURE: Wherever possible I use referral links, which means if you click one of the links in this video or description and make a purchase we may receive a small commission or other compensation.
    I am a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and related sites.

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

  • @humm535
    @humm535 4 ปีที่แล้ว +25

    How do you stretch two loops to be a ten minute video?

    • @BrodieRobertson
      @BrodieRobertson  4 ปีที่แล้ว +3

      TH-camr energy

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

      but its 9:51

    • @BrodieRobertson
      @BrodieRobertson  4 ปีที่แล้ว +1

      Yeah I know I should have stuck something on the end to get it to 10 minutes

    • @MoreChannelNoise
      @MoreChannelNoise 4 ปีที่แล้ว

      ha ha, he still got 60+ likes so far

    • @MoreChannelNoise
      @MoreChannelNoise 4 ปีที่แล้ว

      @@BrodieRobertson you could have just sang "loopy loopy loopy loop" for a minute.

  • @robertdavis9948
    @robertdavis9948 4 ปีที่แล้ว +3

    If I remember correctly (at least in Pascal and Cobol) the until loop tests the condition at the end of the loop while tests at the top of the loop. I think this might be an important consideration in that an until loop will always execute at least once whereas a while loop may never execute.

    • @humm535
      @humm535 4 ปีที่แล้ว +2

      In sh, `until` checks the condition at the top. In typical structural programming languages in widespread use today, there is no `until` loop, but a `do … while` loop, which checks the condition at the bottom.

    • @robertdavis9948
      @robertdavis9948 4 ปีที่แล้ว

      @@humm535 Weird

  • @Soulthym
    @Soulthym 4 ปีที่แล้ว +2

    You should definitely check out the tool entr, it's way better for the usecase you mentioned. It waits for filechanges to perform an action

  • @computer-love
    @computer-love 4 ปีที่แล้ว +6

    so it's just `while` with an implicit negation? tbh i don't really see the use cases for `until` that couldn't just be a `while !`, unless i'm missing something here

    • @nmertsch8725
      @nmertsch8725 4 ปีที่แล้ว +4

      It can help with readability in large and complicated shell scripts. Especially when negations are everywhere, "until X" is much easier to think about than "while not X", even though they technically are the same thing.

    • @computer-love
      @computer-love 4 ปีที่แล้ว +1

      @@nmertsch8725 fair, although it's mostly the opposite in my experience, i find it easier to parse an explicit negation than to have to remember yet another loop type

    • @BrodieRobertson
      @BrodieRobertson  4 ปีที่แล้ว +1

      It's basically just a more concise way of writing while ! which better describes the loop structure.

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

      @@computer-love "untill true" sounds easier than "while not true" tho :p

  • @user-tw2kr6hg4r
    @user-tw2kr6hg4r หลายเดือนก่อน

    incron is the best way to do what you describe in the beginning

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

    Not exactly related to the video but i usually log the error output of a command to a separate file. For instance if normally the scripts "echoes" success messages to. local/log/script-output.log, then the standard errors of the script's commands go to local/log/script-err. log. This method makes debugging easier when you check your scripts after months of use.

  • @lordofenron
    @lordofenron 4 ปีที่แล้ว

    I think there should also be a comment about how fast you named your patrons. You _must_ have practiced that a lot!

    • @BrodieRobertson
      @BrodieRobertson  4 ปีที่แล้ว

      It's definitely not on the first take most of the time.

  • @senninscorpion
    @senninscorpion 4 ปีที่แล้ว +1

    Pretty useful
    and ... you're welcome =D

  • @jwisemanm
    @jwisemanm 4 ปีที่แล้ว

    The "until" loop was in (Turbo)Pascal, BASIC and a few other old-school languages. Also, "until" is basically the same as " do {} while()" that's present in python, C etc...

    • @BrodieRobertson
      @BrodieRobertson  4 ปีที่แล้ว

      It's a very different structure to a do while loop, you can make them act the same way but it's not the same structure what so ever

    • @jwisemanm
      @jwisemanm 4 ปีที่แล้ว +1

      @@BrodieRobertson OK, you are right. Until does the check before executing the loop. I learned to code using Pascal (in high school a gogleplex years ago) , which has the "until" loop and my brain just linked it with the do-while for some reason.

  • @jord_n
    @jord_n 4 ปีที่แล้ว

    Does this have a problem with large files? I noticed that if you write a file, it appears on the disk the moment it begins being written, not when it finishes. I think accessing a large file while it's being written can be dangerous.

  • @tomershechner
    @tomershechner 4 ปีที่แล้ว

    When supplied with no status argument, the exit command will actually use the status code of the last command executed, not necessarily 0!

  • @edvonrattlehead2135
    @edvonrattlehead2135 4 ปีที่แล้ว +2

    Cobol also has until loops

    • @BrodieRobertson
      @BrodieRobertson  4 ปีที่แล้ว

      I've never touched COBOL before but that's cool

    • @edvonrattlehead2135
      @edvonrattlehead2135 4 ปีที่แล้ว

      @@BrodieRobertson for a Completely Obsolete Bussines Oriented Language it has many cool features

    • @gurdeepgss
      @gurdeepgss 4 ปีที่แล้ว

      Ruby also has it

    • @jwisemanm
      @jwisemanm 4 ปีที่แล้ว

      Pascal has it too.

  • @adamaleksander5226
    @adamaleksander5226 4 ปีที่แล้ว

    Great videos mate! Keep it up!

  • @bradolson8242
    @bradolson8242 4 ปีที่แล้ว

    I think that you stretch out two loops to be a ten minute video for the people who are not up on scripting and who need the explainations. Thanks.

    • @BrodieRobertson
      @BrodieRobertson  4 ปีที่แล้ว

      I've been trying to make it a useful 10 minutes, rather than just 10 minute of filler

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

    Visual Basic has Until-Loops. QBasic might have it as well. (don't use that crap, learn a real programming language ;-P )