Writing your first bash script

  Рет қаралды 4,267

Bread on Penguins

Bread on Penguins

Күн бұрын

Пікірлер: 102
@Cappsy
@Cappsy 2 ай бұрын
Give us this day our daily bread
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
🍞🍞🍞
@SS-gu2tx
@SS-gu2tx 2 ай бұрын
A technically literate and practical Linux KZbinr. I don't think I've ever seen one. Subbed!
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Haha thanks very much! :)
@johnbowles4754
@johnbowles4754 2 ай бұрын
Me too 😊
@OldDogNewLinux
@OldDogNewLinux Ай бұрын
There are those who know how to streamline the code you showed, but I appreciate that you explained variables, if, case, sed, & awk in just a few lines of code in just 16 minutes. This was helpful for us noobs out here. Thank you.
@BreadOnPenguins
@BreadOnPenguins Ай бұрын
I appreciate that! I do think it could've been better, but the goal was just some quick and dirty code for showing examples. No problem.
@OldDogNewLinux
@OldDogNewLinux Ай бұрын
@@BreadOnPenguins I'm very new to bash scripting so your "quick & dirty" is very helpful to see the process, as well as the different options you presented. Keeping it simple for noobs such as myself is appreciated. Knowing there are more advanced ways of doing the same thing is cool, but I'm not quite there yet.
@lupuionut6286
@lupuionut6286 2 ай бұрын
I hope you maintain interest in this channel and that it grows more. There seems to be some sort of Linux oriented market on youtube, currently. I'm a dude working in CI, where we automate stuff a lot using bash scripts. Probably this video would've helped me when I started out with it, like half an year ago.
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
I definitely intend to! Gotcha, it's not a hard learning curve once you've gotten started. Bash scripting is applicable in so many areas, as well.
@DV-ml4fm
@DV-ml4fm Ай бұрын
You can use the select statement to create and display a menu of items to choose from.
@mauriereed3875
@mauriereed3875 2 ай бұрын
The case / esac combination comes from the gentleman who wrote the Bourne shell and comes from the Algol programming language which used reversed keywords to mark the end of code blocks. Glad that I discovered your channel a short time ago!
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Thank you for answering! :)
@PreRendered
@PreRendered 2 ай бұрын
These kinds of videos, where you use several different tools in combination, really show the strength of command-line proficiency. I learn something from every one of your videos! I would love to see you flex more of your sed/awk skillset because that stuff is fascinating.
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Thanks so much - I'm glad to hear that! I'm definitely intending to make full videos for sed, awk, even grep and other tools.
@BrokenKanuck
@BrokenKanuck 2 ай бұрын
sed and awk are two tools everyone should get to grips with, they're incredibly powerful. Love the vids! Keep it up! Still learning new things even after 30 years of Linux..
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
For sure - I'll 100% be making vids on both at some point. Thanks so much :) Glad to hear.
@JD-du3qe
@JD-du3qe 2 ай бұрын
excellent video, actual practical example demonstrating multiple concepts, unlike some other first bash script videos I've seen. look forward to more from you! thanks
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Thanks very much! :)
@shayanakhavan6002
@shayanakhavan6002 Ай бұрын
I’m glad I stumbled upon your video! My use of bash scripting has been lost over the years
@BreadOnPenguins
@BreadOnPenguins Ай бұрын
Thanks for stopping by! I've got several other vids going over other useful/practical scripts as well
@kfhahn
@kfhahn 11 күн бұрын
awesome video. keep it up!!! way better quality than a lot of linux videos i see (getting to the point, clarity, presentation and audio quality etc)
@Dad-ij2qy
@Dad-ij2qy 17 күн бұрын
I like how the syntax for programming in BASH is so similar to the syntax used in writing C programs -- not exactly, but really close. I suppose it's no big surprise, considering they were both invented at AT&T Bell Labs back in the 1960's/early 70's
@SpaceCatKungFu
@SpaceCatKungFu 2 ай бұрын
Wow, you rule! You're a great teacher; much appreciated!!
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Thank you! :)
@marian.fratica
@marian.fratica 2 ай бұрын
Greetings from Romania! Just discovered your channel. Very well-structured content with very clean explanations from such a young girl. :) You can easily become a teacher. :P Keep up the good work!
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Thanks very much :)
@saiswayamshree
@saiswayamshree 2 ай бұрын
best concise guide. keep making more such videos
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Thank you! Will do
@techanthology
@techanthology 14 күн бұрын
when getting rid of the % on disk used you can also use awk again and specify the delimiter as the % symbol and print out $1 so basically run awk twice in a row...no big deal and I would have probably opted for using sed as well as awk as you did just for demonstration purposes.... well done!
@retagif
@retagif 2 ай бұрын
Thank you very for this on learning bash, truly enlightening video
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Glad it was helpful!
@kalemolala
@kalemolala 2 ай бұрын
the contents you makes are amazing!
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Thank you! :)
@metalmeditations2036
@metalmeditations2036 2 ай бұрын
SWEET! As promised. Sadly I'm too busy preparing for a professional certification exam to dive into this until week after next, but I am excited to get started.
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Good luck with your exam!
@notafbihoneypot8487
@notafbihoneypot8487 2 ай бұрын
Based bash🗿 I'm glad I'm watching this from the terminal
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Heck yeah
@krisdjames
@krisdjames 2 ай бұрын
Closing an if statement with 'fi' is not unique to Bash, it was also the convention in Bourne script, the predecessor to Bash, as well as most other Unix shells, so they just kept it. Dude who wrote Bourne came from Algol 68 where the reverse closing delimiter was originally used. So 'if/fi', 'case/esac' are unique but you close 'do' with 'done' because 'od' was already used. The others like 'while', 'for' or 'until' are called within do and don't need a terminating delimiter. So basically it's just creative arbitrary decisions of old.
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Thanks very much for answering that!
@mrslacker1437
@mrslacker1437 2 ай бұрын
Let's gooo! THANK YOU! Keep up the good work!
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
No problem and thanks for watching! :) Will do
@dralger
@dralger 6 күн бұрын
That's pretty good. When have you started to get into the Linux topic?
@vmisev
@vmisev 29 күн бұрын
Nice tutorial! Not trying to nitpick here, but IMHO there is no need for awk (as much as I love it) in this “fisrt script” guide, one can get same result with simpler: df --output=pcent /home | sed -e 1d -e 's/%//' Other than that, it’s an excellent video!
@BreadOnPenguins
@BreadOnPenguins 29 күн бұрын
Thanks for mentioning! You're right - this guide could've been far cleaner; I was trying to cram in as many tools as possible.
@vmisev
@vmisev 29 күн бұрын
@@BreadOnPenguins I hear you - both sed and awk are very important; personally I’m comfy with sed, but I’m still only learning awk - after 20 years of using it 😄 IMHO, for any user who is new to *n[i|u]x a key thing to learn about and understand first is regex (+ grep and sed) and how to use them as ‘filters’; learning about scripting is much easier after that. I mean, even MS Word and InDesign users can benefit greatly by learning elementary regex 😎
@lautaroliva18
@lautaroliva18 2 ай бұрын
Hey Bread, great vid! Also, where do you find your wallpapers?? Thery're great
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Thank you! :) Everything from stock photo sites, to /wg/ threads, to looking through work from artists and photographers
@MocanuAndreiCristian
@MocanuAndreiCristian 2 ай бұрын
Hey, I like your theme. Your Terminal looks great, your Desktop looks amazing. Would you mind sharing your configurations with us?
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Thank you! I have a few videos going through how I've configured some aspects and will make more on the subject. I will eventually make a repo for dotfiles (but I'll have to clean up and organize everything neatly, first).
@AshesWake-sf7uw
@AshesWake-sf7uw 2 ай бұрын
Penguinz0 if he was really cool linux person! Love your videos
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Haha thanks so much!
@null11q
@null11q 2 ай бұрын
Luke doesn't care about noobs! Meanwhile, Luke with his AI girl form:
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Lmao
@xmvziron
@xmvziron Ай бұрын
1:37 Fun fact: you don't even need to look beyond Linux to see that, NixOS doesn't have /bin/bash, so you are forced to put /usr/bin/env bash in the shebang. /bin/sh does exist though.
@BreadOnPenguins
@BreadOnPenguins Ай бұрын
Good to know! All the more reason to use a universally applicable shebang
@aidenmiller893
@aidenmiller893 2 ай бұрын
Super useful content, ty
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Glad to hear! Np
@simon7149
@simon7149 2 ай бұрын
You can use cut -d'%' -f1 instead of sed. Might be a little bit faster
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
For sure, I was going to use cut but figured it was better to introduce people to awk and sed.
@dekooks1543
@dekooks1543 2 ай бұрын
not sure if anybody asked before but what keyboard do you use ?
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
It's a razer blackwidow v4 atm, but I'm only using it because I got it cheaply from a friend - honestly I wouldn't recommend it since I've had several issues with switches becoming unresponsive, apparently this is a common issue with this model
@karshPrime
@karshPrime Ай бұрын
the fastest penguin species is the gentoo penguin, which can reach speeds of up to 36 kmph when swimming
@BreadOnPenguins
@BreadOnPenguins Ай бұрын
Hence the distro name!
@nikospitr
@nikospitr 2 ай бұрын
Why the double brackets in " if [[ $myvar -gt 90 ]] ??? Are they really necessary? Also, out of curiosity, why the case needs double ;; to separate choices?
@AnalyticMinded
@AnalyticMinded 2 ай бұрын
I know you are doing beginner-level tutorials for now, but I hope one day you make one about the more obscure aspects of utilities like sed, awk, xargs, grep, etc. Oh, and regex... :P
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Yeah, those are worth going over especially for maximizing efficiency - I'll keep it in mind. :D
@astrx2
@astrx2 2 ай бұрын
Can you make a video about your vim setup ?
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Hello, sure! It's on the to-do list :)
@astrx2
@astrx2 2 ай бұрын
Thank you, you are the best creator !
@vinay_dias
@vinay_dias 2 ай бұрын
A penguins black and white colouring is called counter-shading.
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Hey that's an interesting one, I just looked it up since I hadn't known about it before, apparently it applies to many different animals in order to camouflage. Thanks for sharing!!
@slimkid0225
@slimkid0225 Ай бұрын
BashShcripting🎉
@Lucaux
@Lucaux 2 ай бұрын
any chance we will see u using wayland ??
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
I'll probably make a video about it at some point :)
@VioletJewel1729
@VioletJewel1729 2 ай бұрын
woo woo another good video hehe ^_^
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Thank you!
@TrustJesusToday
@TrustJesusToday 2 ай бұрын
Fun stuff.
@wilk85
@wilk85 2 ай бұрын
Hope you are using shell check in daily 'bashing'?
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
That's a useful too as well :)
@wilk85
@wilk85 2 ай бұрын
@@BreadOnPenguins yep, it will keep you on track with latest syntax
@Brosmule
@Brosmule 2 ай бұрын
you give off MoistCr1TiKaL vibes
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Lol I've gotten that a couple times now
@VioletJewel1729
@VioletJewel1729 2 ай бұрын
double quote "$variables" (almost) always hehe. and double quote "$(captured subshells)" hehe.
@synoim
@synoim 2 ай бұрын
You're so cool lol
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Lol thanks!
@shawnlowery6246
@shawnlowery6246 2 ай бұрын
Not bash related, but you may want to consider always putting a consistent graphic or photo of a smiling Bread on your video thumbnails. This Bread video almost got overlooked on my little phone.
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Thanks for pointing that out! I'm still experimenting with what thumbnail style works best
@HaukeLaging
@HaukeLaging 2 ай бұрын
The shebang line does not tell the shell how to run the script, it tells the kernel how to run the script. It is rather strange to pipe output from awk (the much more powerful tool for text modification) to sed. The solution is to do that in awk (value=$5; sub("%","",value); print value) or in bash: myvar=$( ... ) myvar="${myvar%\%}" But you need neither awk nor sed, you can do that in bash directly: df -h / | ( while read dev v2 v3 v4 percentage rest; do [[ $dev != /dev/* ]] && continue; echo "$percentage"; done )
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
I did want to show both awk and sed in the video since those are commonly used tools that are worth introducing, even if that's not the "best" way for that particular example. Regardless, I appreciate the full explanations - thanks for commenting!
@OldDogNewLinux
@OldDogNewLinux Ай бұрын
​@@BreadOnPenguins That's awesome that @HaukeLaging was able to condense the script down to one or two lines. Something to grasp in the future as I learn to crawl before I can run. Thank you for explaining awk & sed. I'm new to bash scripting, just a couple of months now and I'm loving the sed command. It's so powerful and yet I know only 10% of it's capability.
@Gigusx
@Gigusx 2 ай бұрын
There are penguins in South America
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
South America has some very distinctive penguins! The Humboldt penguin is a cool species, super interesting coloring
@Gigusx
@Gigusx 2 ай бұрын
@@BreadOnPenguins They do have cool coloring! The beaks as well :D
@lukegallo1272
@lukegallo1272 2 ай бұрын
Luke Smith transitioned? I was wondering where he went... makes sense... typical linux chud
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Lmao
@CyperN077
@CyperN077 2 ай бұрын
I use the more portable #!/use/bin/env bash
@BreadOnPenguins
@BreadOnPenguins 2 ай бұрын
Yup that's what I would recommend :)
@samoylov1973
@samoylov1973 Ай бұрын
Nice work! Keep it up! (I get it - you want to show several commands. At least you said it in comments) But - your code could and should be better. Why use more than you actually need for a simple task. #!/usr/bin/env bash clear # Prints disk info: essentials df -h | awk '/\/$/ {print "Used: "$3"\t Available: "$4}' And of course you can do more elegantly with "if then else" statements. DT compared you with Luke Smith. So, why not watch Luke's "Never say "If" writing a Bash script" wonderful video? 😺
@BreadOnPenguins
@BreadOnPenguins Ай бұрын
Hello, thank you for commenting! I have indeed seen Luke's video; if I recall, there was significant debate in the comments over concise vs elegant. Verbosity can be appropriate in the circumstance that others need to quickly and easily understand your code. Given the concept of this video, my priority was packing in as much as possible. I agree that the end result was certainly not elegant, lol But, especially for personal projects, I prefer concise code, and yes, I do avoid if statements! :-)
Using Bash and the Terminal to view info about your Linux system
14:00
Bread on Penguins
Рет қаралды 2,8 М.
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 158 МЛН
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 7 МЛН
fzf, the Unix terminal fuzzy finder
10:02
Bread on Penguins
Рет қаралды 4 М.
More shell tricks and bash wizardry !
12:13
Bread on Penguins
Рет қаралды 6 М.
Andrew Kelley   Practical Data Oriented Design (DoD)
46:40
ChimiChanga
Рет қаралды 149 М.
Librewolf: the best browser?
12:30
Bread on Penguins
Рет қаралды 25 М.
Let's Write A Script! | How To Create BASH Scripts In Linux
49:45
Joe Collins (EzeeLinux)
Рет қаралды 26 М.
Cliphist script, and my new github
16:24
Bread on Penguins
Рет қаралды 4,5 М.
Nix explained from the ground up
23:39
Surma
Рет қаралды 74 М.
Creating a window - Software from Scratch
1:04:12
Muukid
Рет қаралды 173 М.
Linux shell magic tricks 🪄
10:57
Bread on Penguins
Рет қаралды 8 М.
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 158 МЛН