Command Substitution: Can you return data instead of exit codes in Bash? | #3 Practical Bash

Sdílet
Vložit
  • čas přidán 24. 07. 2019
  • It seems bash only allows us to return an exit code from a function and not data like in other programming languages? So what do we instead? Can command substitution come to the rescue? In this video you'll learn how to safely pass data from one function in your script to another
  • Věda a technologie

Komentáře • 14

  • @bernhardkern629
    @bernhardkern629 Před 4 lety +6

    yay, my first youtube comment, just to tell you that your video series is great. Watched the https/tls video and landed in your bash series.

    • @kubucation
      @kubucation  Před 4 lety

      Thanks! I feel honored to receive your first ever youtube comment :-)

  • @ernestogutierrez7877
    @ernestogutierrez7877 Před 3 lety +1

    Had I known function return statements where meant for returning exit codes (0-255) back when I started coding bash scripts, I would have saved myself a lot of troubleshooting time :S
    Great video mate!

  • @mithunmanoharmithun
    @mithunmanoharmithun Před 4 lety +1

    This series is awesome. Thanks !

  • @blank-vw2sb
    @blank-vw2sb Před 2 lety

    Love the series. Thanks!!

  • @jamesw6949
    @jamesw6949 Před 4 lety +3

    Introduced me to shellcheck, thanks!

    • @kubucation
      @kubucation  Před 4 lety +1

      And you just gave me the idea to create a video about shellcheck. Thanks :)

    • @jamesw6949
      @jamesw6949 Před 4 lety

      @@kubucation :)

  • @soufianta8374
    @soufianta8374 Před 10 měsíci

    Hi, this is one of the weird things I took time to understand. Actually, bash shouldn’t be compared to other languages (data types). Bash was supposed to run external binaries/commands that do their stuff and binaries don’t need to play with return values of other binaires. Nice video btw

  • @VoltVandal
    @VoltVandal Před 4 lety +2

    thanks, very understandable

    • @kubucation
      @kubucation  Před 4 lety

      thanks a lot, very glad to hear :)

  • @loveanimals-0197
    @loveanimals-0197 Před 4 lety +2

    What if you had multiple echo statements within that called function?

    • @kubucation
      @kubucation  Před 4 lety

      All output that is usually sent to stdout would be caught. A single or multiple echo statements don't make a difference. We only see an echo statement as a "unit" because it automatically appends a new line (
      ) at the end of the line. However, that's just a default setting and you can in fact not add a new line by using "echo -n foo". Similarly the new line would just be caught by the command substitution along with the remaining output.

  • @fuseteam
    @fuseteam Před 3 lety

    part 3?