These are just the best tutorials of anything Linux available on UA-cam. I really like how you let students make mistakes and show what these can lead to. And for anyone that thinks this is tedious, this is the best and really the only way to understand and prevent more serious issues down the line. Thanks for everything Jay!!
Phenomenal guidance Jay! I'm sure if you created a structured System Administrator Linux course that is tailored to a specific certification or maybe even just a broad overview of what is covered in many of the certificates available... many people who are looking to become certified to get into a position would be extremely grateful and would EASILY pay for that course. Your guidance is just out of this world when it comes to Linux. You hit every single aspect of what is needed to fully grasp the concept in a very understandable way. THANK YOU!!!!!
This is the best video on bash scripting I watched. I love how you teach, very well paced for people like me that don't know about exit codes, and you even got the time to explain how "exit" will not run commands after it and how the exit code is modified by echo commands.
(Newby here) For people who also struggle to understand why the exit code isn't being displayed with the "The directory $directory exists" echo output...here is the solution: echo "The directory $directory exists" exit_code=100 else echo "The directory $directory does not exist" exit_code=0 fi echo "Exit code: $exit_code" exit $exit_code In this modified script, the exit code is stored in a variable called exit_code based on the condition that was evaluated. After the appropriate message is displayed, the exit code is displayed using echo, and the script exits with the specified exit code using the exit command. My basic way of understanding it: In order for the exit code to be a part of the echo results...it needs to be defined as a variable within the script and it needs to be echoed along with the script.
I don't know if you get into this in a later video, but exit codes more broadly defined as the exit condition, not necessarily an error. For example, I wrote a C program to check if the current version of the kernel is the same as the latest one in /boot. I exit the program with a exit code 0 if they are the same, and a 1 if they are not the same. The script checks the exit code to determine if the system needs rebooting or not. Both cases are a normal end, but flag a different condition. This is something I learned back in my MS-DOS days, and I was running a BBS with a mailer front end. The mail would exit with a certain errorlevel to start the BBS at the baud rate the person was connecting with. At 1200 baud, the system would drop with a errorlevel of 12 and the batch file would go to the label that would start the BBS at 1200 baud. 56K would exit at errorlevel 56, etc. The front end had a scheduler, too (like cron) and I'd have the nightly and weekly maintenance set up to exit at like errorlevel 140 and 150 respectively, and have the batch file run the maintenance.. Fun times. Anyway, having a script check the exit code can lead to some really flexible decision automation, and not just flagging errors.
Hey man, i'v been trying to learn Linux for a long time and tried many videos to follow on youtube. You are the best among all of em. Can you also please make a video of what should we focus to learn minimum stuff to get a job as a linux sys admin ? i believe it will be very helpful to all the viewers of this channel and really appreciate ur work.
Thank you Jay. This course will save me time. I highly recommend the 'Mastering Ubuntu Server' book by Jay laCroix, it is the same easy to follow style as his videos, just easier to refer back to.
You are really an excellent teacher, your patience to explain a concept is second to none - the best. Thank you! A kind request however is if you can do a series on ethical hacking. I know it tasking, and tedious but it will help the knowledge easily accessible and grasping.
The fact that exit instantly kills the script can be handy to check that, for example, unless a certain file exists everything else should not run. You may see lines of code like this one on the wild: [[ ! -f /some/file/path ]] && exit 1 Except "&&" everything else is covered in this tutorial series, it means "execute the following command ONLY when the first command returns 0"
I guess you can use another approach by saving the exit code as a variable and then accessing it at the end of the script like this (correct me if I am wrong): #!/bin/bash directory=/notexist if [ -d $directory ] then exit_code=$? echo "The directory $directory exists." else exit_code=$? echo "The directory $directory does not exist." fi echo "The exit code for this script run is $exit_code."
I think everybody would benefit from a system where you label a video either beginner, intermediate or expert, this way you do not have to repeat yourself so much. I notice that you may be a little to overly friendly to the user which can use a lot of time.
Checking the exit code directly within the if statement is unnecessary since if statements are driven by exit codes behind the scenes. The test clause of the if statement runs the test command and then decides what to do if the exit code is success or failure.
There is something I don't understand. You declared a variable called package with the htop value but you didn't use these "" or ''. So how will bash interpret a variable with the string without "" or ''. If we put the htop inside "", how will bash interpret the package?
If the string of text doesn't include spaces it's not necessary to use "". Bash will interpret package=htop the same way as package="htop". Try this two commands: echo htop echo "htop" Both will have the same result: htop
Hi BolekWu, Actually "(Double Quotes)" and '(Single Quotes)'----> These plays an important role in some scenarios. For Example, If we want to print a name/word-----> In this scenario, Mentioning Single Quotes /Double quotes are not Mandatory. But, If we want to print a simple sentence called (HELLO WORLD)----->In this scenario, Mentioning single Quotes / Double Quotes are Mandatory; because Between Hello and World; Space is available. Here Bash cannot recognise/print the sentence without quotes. ***Here are some simple examples that u can understand easily; . . Example: 1 #Using variable as (name) and value is (bash) name=bash (or) name='bash' (or) name="bash" If we do (echo $name) --------------------------------------------------------------------------------------------------------------------->#Output = bash . . Example: 2 #Using variable as (name) and value is (Hello World) name='Hello World' (or) "Hello World" If we do (echo $name) ------------------------------------------------------------------------------------------------>#Output = Hello World . . #The difference between "(Double Quotes)" and '(Single Quotes)' are: *Single Quotes are used to print the sentence/word. *Double Quotes are used to print the existing variable in the sentence. Example: 3 #Using variable as Script compliment=beautiful script="Hello BolekWu, You have a $compliment beard i've ever seen." If we do (echo $script) ---------------------------------------------------------------->#Output = Hello BolekWu, You have a beautiful beard i've ever seen. Here, In the ex:3 We are using existing variable in the variable. In this case we have to use DOUBLE QUOTES.
Hi @Jay , I was trying to install the package "htop" on mac OS but it throws an error 'Unable to locate a Java runtime'. Is it necessary to install Java? or Am i doing something wrong?
For bash: '1': Catch-all for general errors '2': Misuse of shell builtins (according to Bash documentation) '126': Command invoked cannot execute '127': "command not found" '128': Invalid argument to exit '128+n': Fatal error signal "n" '130': Script terminated by Ctrl + C
Very nice session , can someone help me i was trying to use this line in my script but whenever it asks for password it got stuck there and can't continue for other users check . how to get out of it and continue the rest of the commands ? tried -"T" or "timeout" but no luck as timeout is not inbuilt . # su - user1 -c 'sudo -l' We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things: #1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility. Password: thank you .
Hey Jay, you keep doing something which I find annoying. I was watching at the 2:44 mark and the amount of time the command is displayed on the screen is less than a second. I know you type fast, but I read slow. Perhaps you could, in future videos, type out the command so we "old slow farts" can freeze the screen so we can follow along with the command before it's gone again. I've rewound this particular moment in time several times, and on my phone, with its small screen, it's not a fun thing to try because I keep over/under jumping. Please... please... KEEP THE COMMANDS ON THE SCREEN FOR LONGER THAN A SLIVER OF TIME before you press the ENTER key.
Hey good stuff. Thanks for making these videos. They have been helpful for getting me familiar with the syntax and BASH/linux environment. A note - The script at around 20 minutes, with successful exit code of 0 is correct, even though the conditional statement is FALSE. This is because there isn't an error. It's simply a conditional check to direct the flow of commands. And thanks for the handy explanation of forcing exit codes. Good to know. I was wondering if we can put a non-number as the exit code, like a string or text. 🙃
If you wanted to here's my way of checking exit codes reliably and easily. check_status() { STATUS=$STATUS If [ $STATUS == 0 ]; then echo "OK" else echo "FAIL $STATUS" fi } sudo apt-get update; STATUS=$? STATUS=$STATUS check_status You can use an argument instead of a variable passed to it if you wanted to.
These are just the best tutorials of anything Linux available on UA-cam.
I really like how you let students make mistakes and show what these can lead to. And for anyone that thinks this is tedious, this is the best and really the only way to understand and prevent more serious issues down the line. Thanks for everything Jay!!
Greeting from Russia. I really enjoyed it.
Excellent series! I am a newbie but your tutorials are easy to understand. Thank you Sir!
You sir are an excellent teacher! This series is great, thank you for making it. :)
Phenomenal guidance Jay!
I'm sure if you created a structured System Administrator Linux course that is tailored to a specific certification or maybe even just a broad overview of what is covered in many of the certificates available... many people who are looking to become certified to get into a position would be extremely grateful and would EASILY pay for that course. Your guidance is just out of this world when it comes to Linux. You hit every single aspect of what is needed to fully grasp the concept in a very understandable way.
THANK YOU!!!!!
This is the best video on bash scripting I watched. I love how you teach, very well paced for people like me that don't know about exit codes, and you even got the time to explain how "exit" will not run commands after it and how the exit code is modified by echo commands.
(Newby here) For people who also struggle to understand why the exit code isn't being displayed with the "The directory $directory exists" echo output...here is the solution:
echo "The directory $directory exists"
exit_code=100
else
echo "The directory $directory does not exist"
exit_code=0
fi
echo "Exit code: $exit_code"
exit $exit_code
In this modified script, the exit code is stored in a variable called exit_code based on the condition that was evaluated. After the appropriate message is displayed, the exit code is displayed using echo, and the script exits with the specified exit code using the exit command.
My basic way of understanding it: In order for the exit code to be a part of the echo results...it needs to be defined as a variable within the script and it needs to be echoed along with the script.
I don't know if you get into this in a later video, but exit codes more broadly defined as the exit condition, not necessarily an error. For example, I wrote a C program to check if the current version of the kernel is the same as the latest one in /boot. I exit the program with a exit code 0 if they are the same, and a 1 if they are not the same. The script checks the exit code to determine if the system needs rebooting or not. Both cases are a normal end, but flag a different condition.
This is something I learned back in my MS-DOS days, and I was running a BBS with a mailer front end. The mail would exit with a certain errorlevel to start the BBS at the baud rate the person was connecting with. At 1200 baud, the system would drop with a errorlevel of 12 and the batch file would go to the label that would start the BBS at 1200 baud. 56K would exit at errorlevel 56, etc. The front end had a scheduler, too (like cron) and I'd have the nightly and weekly maintenance set up to exit at like errorlevel 140 and 150 respectively, and have the batch file run the maintenance.. Fun times.
Anyway, having a script check the exit code can lead to some really flexible decision automation, and not just flagging errors.
Thanks man I am learning this tutorial on android in termux but your videos are helpful 👍
Hey man, i'v been trying to learn Linux for a long time and tried many videos to follow on youtube. You are the best among all of em. Can you also please make a video of what should we focus to learn minimum stuff to get a job as a linux sys admin ? i believe it will be very helpful to all the viewers of this channel and really appreciate ur work.
Amazing vids! Thanks for breaking things down so simply for the little guy!
Thank you Jay. This course will save me time. I highly recommend the 'Mastering Ubuntu Server' book by Jay laCroix, it is the same easy to follow style as his videos, just easier to refer back to.
You are really an excellent teacher, your patience to explain a concept is second to none - the best. Thank you!
A kind request however is if you can do a series on ethical hacking. I know it tasking, and tedious but it will help the knowledge easily accessible and grasping.
Your cadence/pacing matches "Amon Tobin - Nova" really nicely.
Sheesh! This was great. I appreciate you and your teaching style!
same same
Just commenting so youtube knows this is important!
love this series thank oyu
Great teaching style. It feels like I am in the classroom :)
best coach. love from circassia!
The fact that exit instantly kills the script can be handy to check that, for example, unless a certain file exists everything else should not run.
You may see lines of code like this one on the wild:
[[ ! -f /some/file/path ]] && exit 1
Except "&&" everything else is covered in this tutorial series, it means "execute the following command ONLY when the first command returns 0"
Very lucid and great lesson
Yo make AMAZING videos Jay !!
Best linux tuts i;ve seen thanks!
Super handy stuff here. I'll be using this for an upcoming script. Thanks!
Tnx captain❤
Excellent, I wanted to take over the world but I will just take over my computer using this
Just great!! Thanks!!!
Learned exit code and if statements
Dziękujemy.
I guess you can use another approach by saving the exit code as a variable and then accessing it at the end of the script like this (correct me if I am wrong):
#!/bin/bash
directory=/notexist
if [ -d $directory ]
then
exit_code=$?
echo "The directory $directory exists."
else
exit_code=$?
echo "The directory $directory does not exist."
fi
echo "The exit code for this script run is $exit_code."
These were great
Awesome!!! Thanks
Nice. I learned some things watching your video. My only nit is, the /etc directory is pronounced "etcetera", not "et-sea".
it is faster to say atsee then etcetera, this is why people do this
I think everybody would benefit from a system where you label a video either beginner, intermediate or expert, this way you do not have to repeat yourself so much. I notice that you may be a little to overly friendly to the user which can use a lot of time.
This.
thanks so much
You gotta show us how to make some beats on FL Studio too :P
Jokes aside great series!!
Thanks
Checking the exit code directly within the if statement is unnecessary since if statements are driven by exit codes behind the scenes. The test clause of the if statement runs the test command and then decides what to do if the exit code is success or failure.
Wonderful
did you get the hardware acceleration working on proot ubuntu?
great video :)
There is something I don't understand. You declared a variable called package with the htop value but you didn't use these "" or ''. So how will bash interpret a variable with the string without "" or ''. If we put the htop inside "", how will bash interpret the package?
If the string of text doesn't include spaces it's not necessary to use "". Bash will interpret package=htop the same way as package="htop".
Try this two commands:
echo htop
echo "htop"
Both will have the same result: htop
@@BolekWu thanks.
Hi BolekWu,
Actually "(Double Quotes)" and '(Single Quotes)'----> These plays an important role in some scenarios.
For Example, If we want to print a name/word-----> In this scenario, Mentioning Single Quotes /Double quotes are not Mandatory. But, If we want to print a simple sentence called (HELLO WORLD)----->In this scenario, Mentioning single Quotes / Double Quotes are Mandatory; because Between Hello and World; Space is available. Here Bash cannot recognise/print the sentence without quotes.
***Here are some simple examples that u can understand easily;
.
.
Example: 1
#Using variable as (name) and value is (bash)
name=bash (or) name='bash' (or) name="bash"
If we do (echo $name)
--------------------------------------------------------------------------------------------------------------------->#Output = bash
.
.
Example: 2
#Using variable as (name) and value is (Hello World)
name='Hello World' (or) "Hello World"
If we do (echo $name)
------------------------------------------------------------------------------------------------>#Output = Hello World
.
.
#The difference between "(Double Quotes)" and '(Single Quotes)' are:
*Single Quotes are used to print the sentence/word.
*Double Quotes are used to print the existing variable in the sentence.
Example: 3
#Using variable as Script
compliment=beautiful
script="Hello BolekWu, You have a $compliment beard i've ever seen."
If we do (echo $script)
---------------------------------------------------------------->#Output = Hello BolekWu, You have a beautiful beard i've ever seen.
Here, In the ex:3 We are using existing variable in the variable. In this case we have to use DOUBLE QUOTES.
Hi @Jay , I was trying to install the package "htop" on mac OS but it throws an error 'Unable to locate a Java runtime'.
Is it necessary to install Java?
or
Am i doing something wrong?
Maybe a silly question, but is there a predefined list of 'exit codes' and their meanings available to look at or download? -thanks.
You can look them up using the "man pages". E.g., "man ls" and scroll to the bottom and look for "Exit Status".
For bash:
'1': Catch-all for general errors
'2': Misuse of shell builtins (according to Bash documentation)
'126': Command invoked cannot execute
'127': "command not found"
'128': Invalid argument to exit
'128+n': Fatal error signal "n"
'130': Script terminated by Ctrl + C
@@cognoscibilis Don't forget:
'255': Exit status out of range
Mine keeps saying htop failed to install, despite installing sucessfully.
Very nice session , can someone help me i was trying to use this line in my script but whenever it asks for password it got stuck there and can't continue for other users check . how to get out of it and continue the rest of the commands ? tried -"T" or "timeout" but no luck as timeout is not inbuilt .
# su - user1 -c 'sudo -l'
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
Password:
thank you .
Hey Jay, you keep doing something which I find annoying. I was watching at the 2:44 mark and the amount of time the command is displayed on the screen is less than a second. I know you type fast, but I read slow. Perhaps you could, in future videos, type out the command so we "old slow farts" can freeze the screen so we can follow along with the command before it's gone again. I've rewound this particular moment in time several times, and on my phone, with its small screen, it's not a fun thing to try because I keep over/under jumping.
Please... please... KEEP THE COMMANDS ON THE SCREEN FOR LONGER THAN A SLIVER OF TIME before you press the ENTER key.
❤❤❤❤❤
👍
10:25
☯🙏
what is the difference between "which" and "command -v"? You used later one in the previous video, here you're using "which"
Hey good stuff. Thanks for making these videos. They have been helpful for getting me familiar with the syntax and BASH/linux environment.
A note - The script at around 20 minutes, with successful exit code of 0 is correct, even though the conditional statement is FALSE. This is because there isn't an error. It's simply a conditional check to direct the flow of commands.
And thanks for the handy explanation of forcing exit codes. Good to know. I was wondering if we can put a non-number as the exit code, like a string or text.
🙃
If you wanted to here's my way of checking exit codes reliably and easily.
check_status() {
STATUS=$STATUS
If [ $STATUS == 0 ]; then
echo "OK"
else
echo "FAIL $STATUS"
fi
}
sudo apt-get update; STATUS=$?
STATUS=$STATUS check_status
You can use an argument instead of a variable passed to it if you wanted to.