Crash-Course in using `getopts` to parse Command Line Arguments in Bash!

preview_player
Показать описание
Recorded during an Instagram live-stream - to learn more you can run:

help getopts

in your bash shell to see all of the possible options.

🔗 More Links

📖 Keywords
you suck at programming #programming
#devops #bash #linux #unix #software #terminal #shellscripting #tech #stem
Рекомендации по теме
Комментарии
Автор

For a second, I was going to question the choice of setting a variable to "true" or "false"... until you did `if $u`. Well played, sir. You should explain why that works.

greyfade
Автор

thanks getopts was very intimidating to me before, going rewrite all scripts with it now

rehiteco
Автор

Daaamn, i was just making a script for fun looking into this, deff gonna chek it out (lord plz give me vacation). Thxs bash jesus!

Sft_bb
Автор

getopt > getopts

getopts is so last century.

You should always use long options in articles, demonstrations, and scripts. Especially when the intended audience is inexperienced.

In six months will your readers think that ‘grep -i’ means --input or --ignore-case? Will they confuse ‘cut -d’ and ‘tr -d’ compared with ‘cut --delimiter’ and ‘tr --delete’?

Will learning 'rm --force --recursive' give them just a millisecond pause to keep them from doing something catastrophic?

steveedwards
Автор

I'd like it if you covered bash coprocesses, and what they are good for, sometime soon. It's one feature I have not really been able to wrap my head around.

But maybe you'd have to introduce named pipes and the like first?

davidh.
Автор

also
what is echo $? ? is it "print last program exit value"? does that thing have a name? like an exit buffer? thanks!

jaytea
Автор

Idea for short:

why bash as language/community chose to execute after errors, and have a typical script flow only with -e flag?

yomajo
Автор

It might be worth it to do a video on how to support long arguments like --help in a bash script. Using getopts alone can't do that.

TomGrubbe
Автор

Instructions unclear. I ended up deploying my Bash script via Argo CD. 😮

lindhe
Автор

dope
quick question: for command line c programs, do devs usually manage options internally? or is there a getopts function in c?

jaytea
Автор

Why do you Livestream on Instagram? I'd love to watch your stream if it were on YouTube or twitch but I refuse to download a Meta app

portobellomushroom
Автор

Why shebang usr bin env bash instead of bin bash

NootNooter
welcome to shbcf.ru