For anyone else who followed along and ran into the issue with the second script of having no default output for when the user doesn't input any flags, add this to the script after the while loop: if (( $OPTIND == 1 )); then echo "Hello, $NAME!" # or whatever you want the default option to be fi And in the first script if you want to make it so the user input matches the case statement case-insensitively (i.e. "Arch" or "arch" etc.) include the line "shopt -s nocasematch" at the top of the script.
@BrickTamlandOfficial
24 күн бұрын
that first script you made is great and you can adapt it into a menu with various options like to run apt update or update docker containers etc. very cool.
@DistroTube
24 күн бұрын
Glad you found it useful.
@anon_y_mousse
20 күн бұрын
You should also demonstrate shell pattern matching with cases so that you don't have to have a huge pipe of every case where a given distro might be entered, such as *[Dd]istro*. Also, the Slackware package manager is indeed unknown, so spot on.
@siljrath
25 күн бұрын
Not watched this yet, but: The expression on the thumbnail.... Yes. This is the correct expression, for case statements. :)
@siljrath
25 күн бұрын
so very looking forward to this one, bumped to head of next playlist :D
@koduflower2000
25 күн бұрын
yeah i get that joke :D
@12Q46HPRN
25 күн бұрын
Thank you for this. Yet another reason I keep referring ppl to your channel.
@DistroTube
24 күн бұрын
Much appreciated!
@YTit69
21 күн бұрын
@DistroTube Great thing again! Propose you to make few videos about how to make useful things in everyday usage. Or some direct situations likes Docker, Ansible, backups, proper linux setup for security
@flipinfin
Күн бұрын
Great explanation very educational. So basically you want to write your scripts as TRUE statements?
@pdr.
25 күн бұрын
Couple of notes to help with engagement: Normally, local variables are in lower case by convention, i.e. "$distro" and should be quoted when used. This is for safety, and a good habit even when not strictly required. Patterns in case statements can be globs, e.g. \*[Mm]int\* or \*buntu\* which will cover a lot of cases. You could also use lsb_release -si but I guess that's not quite the same script then.
@pdr.
25 күн бұрын
Please ignore the "\"s above, but without them it was interpreting the "*"s as markup for bold.
@mats4554
16 күн бұрын
Is the while loop necessary for the script in the video? I mean can you simply do: getopts "aem" Case ... Esac
@pdr.
15 күн бұрын
@@mats4554 Yes, it's necessary. The options are parsed sequentially. It works very much analogously to C's getopt(3).
@pdr.
15 күн бұрын
@@mats4554 Well, actually, technically you're right since only one flag is used at a time, but since it's just example code I think it's good to show the loop like in the more general case.
@mats4554
15 күн бұрын
@@pdr. Can you provide an example where it is necessary, I don't quite get it ...
@AlexDavid-s1p
25 күн бұрын
14 seconds is crazy
@marsdrums6298
24 күн бұрын
So, I'm not familiar with programming language and I see that you used /dev/null which there is a file named null in /dev. Mine had nothing in it. So, either no actual data gets written to that file or it's automatically deleted? I'm half tempted to try this out and see if it will actually write to /dev/null... EDIT: Okay, so to answer my question, I recreated the Greetings script and... No, it does not write to the /dev/null file. So, it must just get erased and never seen again or does it actually go to another file somewhere?
@DistroTube
24 күн бұрын
So.../dev/null is a special file on your system. Anything written to it disappears. Poof!! It's gone! :D
@amos660
25 күн бұрын
DT!!! what's up,baby
@halfsourlizard9319
24 күн бұрын
`fi` / `esac` were weird choices, even for the time ... `end if` / `end case` seem like they would have made more sense -- and been only trivially more typing.
@ralphwuu
25 күн бұрын
Bro's face when there's another scripting language with switch statements (definitely not my face)
@halfsourlizard9319
24 күн бұрын
6:38 E&E
@MichaelWilliams-lr4mb
25 күн бұрын
Void Linux got no love in the Favorite Distro script. :(
@egidijus6973
25 күн бұрын
"esac" is just "case" backwards.
@maxdjently
25 күн бұрын
That was fun! Check out my Bash Script for Termux on Android, Ziggle Wump. A simple batch media compressor. Search on Google and you will find my Reddit post showing you what it does and how to use it.
@jacobwerner8533
24 күн бұрын
my brain instinctly wants to do c stuff when i do bash. another way i came up to do the last example is: #/bin/bash echo -n "Enter your name: " read NAME case $1 in a|-a) echo "Good morning, $NAME!" ;; e|-e) echo "Good evening, $NAME!" ;; *) echo "Hello $NAME" ;; esac now you can enter flags by letter or with hyphen, and no error message.
Пікірлер: 32