Bash Scripting 4 -- How Bash Scripts Work

preview_player
Показать описание
How does bash scripting work? An introduction to the "shebang" line, bash exit codes, and different ways of running bash scripts. You need to know this before starting to write bash scripts!

Рекомендации по теме
Комментарии
Автор

This is the most amount of information I've learned inside of 12 minutes in a long time. Thank you!

MikeDawson
Автор

Your vids are pure gold especially these series, please continue.

Czarmzy
Автор

Bash Scripting 4 -- How Bash Scripts Work
My notes:


What command do you use to find out where the Bash binary is?
(hint: The first thing you declared in every script)


which bash
(will output /bin/bash or other location it is stored in)


-


When you create a script, why should you use the file ending .sh?
(even though file endings won't matter to the shell?)


Because the it will be easier for the people who come after you to understand what it is


-


Return values can be anywhere between 0 through....

..255


-


When you use 'exit' at the end by itself, what will the shell do?


It will look for the last item that was called and will return that as the program's return value
(as long as it returns 0/has no errors)


-


When you use 'exit $?', what are you doing in your program?


You are showing that you are intentionally exiting and telling the program to output the last item that was called as the output


-


When you execute a file, what permission do you need to make sure that you have?


execute
(use chmod on the file to allow execution of it)


-


Running a program in the shell:
Why should you use: 'source helloworld.sh' rather than 'bash helloworld.sh' ?


Because you will have access to the variables and information stored inside the script in your current bash session
(makes it easier because you won't have to run things over and over again to modify certain elements)


-


What is the difference between these two:
source helloworld.sh
. helloworld.sh


There is no difference, both are interchangeable


-


Tell me if there is anything that I missed or got wrong.
Have a safe and productive day.

samuraijack
Автор

Excellent series, taught in a clear, simple and entertaining way by a good teacher. Thank you!!!

MrWARRIORMONKS
Автор

thank you so much for making these series.

davidsun
Автор

Dave, awesome video here, really accessible. Any chance on a follow up/continuation of this series in the near future?

mattb
Автор

Very useful.
Thank You for sharing your knowledge.

samdavepollard
Автор

Hi,
Sorry ignore my question. Just watching a few seconds more gave me the answer. It is at the kernel level as you said. I never knew that before!
Thanks

linuxmq
Автор

Hey, I was following along fine but for some reason now I'm not able to execute anything. What have I messed up. Sorry, user is not allowed to execute '/bin/bash' as root on hostname

kgaurav
Автор

Wanted to know what if changing the $message variable after sourcing the script would actually change the variable in the script or just in the shell session. Turns out it just changes the value of the variable in the login shell and not the script. Sourcing the script again will reset $message variable in the login shell to the value specified in the script. Great stuff!!

aayushmaurya
Автор

What is the difference between /bin/bash and /usr/bin/bash? My output on which bash shows /usr/bin/bash.

noahark
Автор

Hey, thank you for this vedio. in this video 1 is terminal and another is which program ? could you tell me? (i just try to learn about Linux)

aekraj
Автор

how to exit in the bash -4.3 ?Already tried exit did not work

rebekamendonca
Автор

Very nice videos.
Something that I never understood. Why "#!/bin/bash" is so important in the first line of a script if the "#" starts a "comment line" that is "ignored"?
What is the process behind the scripting language that requires that specific line? I would understand if there wasn't any "#" first.
Thanks

linuxmq
Автор

I just did a test and found out that only "./test.sh" reads the interpreter in the 1st line. I found this by mistaken the bash's path.
All other 3 options, that is ". test.sh", "source test.sh" and "bash test.sh" have returned the expected output, whilst the 4th one returned "bash: ./test.sh: bin/bash: bad interpreter: No such file or directory"

jimkats
Автор

the '$?' was a bit confusing. some additional explanation/examples would have helped, but besides that, pretty good

humbe-oh
Автор

Ahh, yes. The shebang. The more elusive cousin to the slightly lesser known “exclamuestion” mark.
All rights reserved, patent pending.

EndrChe
Автор

I hope you’ve left fb and Twitter by now

caseywinters
Автор

u take really a lot time to tell simple things otherwise ur tutorials are good

soul-monk
Автор

If you write a script for the bash, you should call it .bash

nagiostest
visit shbcf.ru