Command Substitution: Can you return data instead of exit codes in Bash? | #3 Practical Bash
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
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.
Thanks! I feel honored to receive your first ever youtube comment :-)
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!
This series is awesome. Thanks !
Love the series. Thanks!!
Introduced me to shellcheck, thanks!
And you just gave me the idea to create a video about shellcheck. Thanks :)
@@kubucation :)
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
thanks, very understandable
thanks a lot, very glad to hear :)
What if you had multiple echo statements within that called function?
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.
part 3?