A Beginner's Introduction to BASH Shell Scripting

Поділитися
Вставка

КОМЕНТАРІ • 231

  • @git_t0v
    @git_t0v 3 роки тому +36

    as soon as he said that he was a late bloomer to linux/bash scripting i was hooked because i am too.
    Thank you!

    • @scootergirl3662
      @scootergirl3662 3 роки тому

      Same here - I am kicking myself for not learning it earlier, but oh well

    • @tylerstevens9022
      @tylerstevens9022 3 роки тому

      as soon as i read this comment he said that lol

    • @anthonydrew9437
      @anthonydrew9437 3 роки тому

      Instablaster

  • @Sarahelizabeth_
    @Sarahelizabeth_ 3 роки тому +40

    I love that you include your mistakes and show how you go about fixing them, super helpful 😁

    • @EzeeLinux
      @EzeeLinux  Рік тому

      It tells the shell that it's a script and tells it what command interpreter to use. #! = script, /binbash = the cli to use.

  • @christinashupa5851
    @christinashupa5851 6 років тому +84

    Thank you, I've been using Linux Mint for a year or so. I'm just starting to play with different commands in terminal and want to learn to use them. Beginners tutorials like this for writing useful scripts is what I was looking for. Thank you again

  • @MdShamimRahman
    @MdShamimRahman 2 роки тому +2

    Much details in everything. People shouldn't fear Linux system if they come to Joe's channel.

  • @ianlong4704
    @ianlong4704 6 років тому +14

    You were reading my mind today. I needed a simple script this morning and had no idea how to make it.

  • @PedroDominguez15
    @PedroDominguez15 3 роки тому +2

    Watching this in 2021 and all I can say is that you sir have inspired me to embark on my forgotten IT Journey. If I make to the big leagues Joe Collins will receive credit. Much appreciated !!

  • @philippe6724
    @philippe6724 Рік тому +1

    Joe, you're just a master at teaching Unix! Thank you for your precious time!

  • @Jegan_Kanthasamy
    @Jegan_Kanthasamy Рік тому +1

    This video is an eye opener for me, I always though Shell scripting is very tough. but after watching your video, It feels easy for me, So I'm gonna give it a try.

  • @goku14139268520
    @goku14139268520 6 років тому +24

    There's something about your scripting videos that I really enjoy.
    I'm a hobiest programmer, and I've written many'a script to make repetitive tasks easier, so I'm no stranger to bash. But even though this video is aimed toward beginner to intermediate users, I find myself drawn in.
    Also, I find the sound of your keyboard kinda relaxing. Almost like ASMR. Lol

    • @Atman89
      @Atman89 2 роки тому +1

      Sounds like you find the sound of his keyboard relaxing.

    • @omarflux1580
      @omarflux1580 2 роки тому +1

      @@Atman89 lol 😂 he just said that

  • @banjoperator
    @banjoperator 6 років тому +4

    for me Mr. Collins.. your goal has been accomplished... another door opened, the light bulb switch flipped on.. .. awesome.. now there is another direcrion to go... who ever would have though that at 57, understanding operating systems and pc's could be fun,,,lol..well done vid as per usual..

    • @asdfghjklasdfghjkl2548
      @asdfghjklasdfghjkl2548 5 років тому +1

      57 and switched to linux??? What not to like here ☺ Welcome to linux my friend 😉

  • @eznix
    @eznix 6 років тому

    Cool video. I started writing scripts about 4 months ago knowing nothing. Google was my best friend. Every time I had an idea, I just googled the question and it got me started. Every question that came up, I googled it and got the answer. Now I am ready for a book, but Google got me started. Thanks.

  • @eyes1719
    @eyes1719 2 роки тому +3

    great video for beginners... and loved how you showed mistakes and how to fix them... look forward to seeing more of your videos

  • @bunman2353
    @bunman2353 Рік тому +1

    you are awesome. Don't be afraid of making mistakes

  • @ericc461
    @ericc461 4 роки тому +1

    Thanks again. Not too fast, not too long. A good review for me.

  • @humanbeing_
    @humanbeing_ 6 років тому +13

    YES!!!!!! 👍👍👍👍 THANKS JOE! I've been waiting for more BASH & Scripting videos from you. The subject matter is interesting and actually incredibly FUN to me!
    And when you went (somewhat) in-depth on several points of your top 5 reasons you love LINUX video yesterday, I thought to myself "hopefully he'll release more BASH / Terminal videos".
    Love that you're back doing *more* LINUX uploads. And you sound happy as well (as a side note) so hopefully your time off served you well 😬
    Cheers!
    H.B.

  • @pullrequest1481
    @pullrequest1481 Рік тому

    God! I just find a gem. Following this with my nokia n900. Thank you ❤

  • @Bit930
    @Bit930 4 роки тому

    I made my first script to run a command on startup for my raspberry pi after watching your video . Thanks keep them videos coming

  • @jeffreynunes2508
    @jeffreynunes2508 6 років тому +1

    Joe clearly you truly belive in in what linux stands for. Free and open!! And so should knowlage!! A great video. And Cleary explained. Thanks for your work!!!

  • @AndrewAHayes
    @AndrewAHayes 6 років тому +3

    I used to use the shell in Amiga-Dos on the Amiga and Xtree in MS-DOS quite a bit, a very long time ago and enjoyed the control I had over the system, I have done a little bit of scripting on Raspians shell on the Raspberry Pi, this has inspired me to take it further!
    Thanks for the video Joe and the book recommendation which I will download and print if it's not too large.

  • @davonuk1
    @davonuk1 6 років тому +4

    Coming from an programming environment, this all makes logical sense to me.
    It is just a matter of learning the proper syntax for bash.

  • @alf.2929
    @alf.2929 6 років тому +22

    Thanks Joe. Just what I needed.

  • @ArSaSixNine
    @ArSaSixNine 3 роки тому +2

    Just saw this other video in which the guy said something like: Oh! It doesn't matter as long as you put .sh at the end.
    For one reason or another, I trust that she bang a lot better than the .sh
    Very cool video, one can tell that you actually have fun doing this kind of thing, at the very least, I know I am.

  • @Hevander75
    @Hevander75 5 років тому +2

    hey man I really appreciate you for taking the time to make this video

  • @skytale35
    @skytale35 4 роки тому

    leaning VIM (VI) is painful, but wow, once you start getting it . . . it is worth the price of admission. If you're aspiring to program, learning VIM is a bonus. VIM commands are available on pretty much every major text editor, and VIM is pretty much like a plague, it is everywhere. I pretty much equate learning VIM to learning scales on a guitar, you can learn to play songs without it, but knowing it makes it easier to learn songs. You should learn it, if for no other reason than you are relatively gifted as a teacher, and if you want to program knowing vim makes you more valuable imho.

  • @ophawku
    @ophawku 6 років тому +3

    Thanks Joe! Good info and glad to see you back in the groove.

  • @Seattlefan77
    @Seattlefan77 5 років тому +5

    This is great. I spent hours perfecting syntax through about an hours worth of videos but had no idea I could run regular terminal commands as scripts. Wow, linux boggles my mind once again. I aways had a group of four or so commands I ran together whenever I booted up, but not more! Im only (what feels like) 1 minute in so I hope to see if this video includes ways to 'trigger(?)' at different times like on startup or just at time increments.
    Ive already watched and liked a few of your videos like shell basics but this little snippet I didnt get from anywhere else boggled my mind. There was another video on bash scripting that demanded I first learn vim, apparently its more powerful than poor 'lil Geany and Sweet Granny Nano. But I don''t need that power right now, drowning men don't need a yacht when a log will do. I could write this stuff with proper 1/2cm indentations on a piece of paper and scan it onto my computer at this point.
    Subscribed thrice over, i'm eating this shit up like i've been starving Cuh

    • @KhadijahCelestine
      @KhadijahCelestine 5 років тому

      have you found crons, which will help you "trigger" your scripts.

  • @mikediaz9033
    @mikediaz9033 2 роки тому

    You're a good Man.
    Software is so Simple.
    I have Mastered Computer Hardware & Architecture. 25 + yrs.
    Memory is extremely important.
    Memory storage and allocation "Structure", is so important.

  • @yankeesouth
    @yankeesouth 3 роки тому +1

    your honesty and candor just got a subscribe from me. Thank you for making this content. I learned from your video.

  • @huckleberry582
    @huckleberry582 6 років тому

    Glad to see you back at what you do so well. Teach on...

  • @MarzJonp
    @MarzJonp 5 років тому +1

    I found this tutorial very comprehensive and a good jump off point to do some research. Thank you.

  • @mcnits
    @mcnits 2 роки тому +1

    Man this is so beautiful! You explain this so well. Thank you so much

  • @SmerrillS
    @SmerrillS 6 років тому +8

    Dude, Joe, this was the video that's gotten a fire under my ass! I've been wanting to learn to code, for a long time, and I've been wanting to dig deeper into using the CLI. I followed the entire video, and created the two scripts you did, following the entire way. Now I'm looking for more resources, because I GOTTA learn more! Thank you for helping me get off my dead ass and do something!

  • @CayoBuay
    @CayoBuay 6 місяців тому

    I've been using GNU/Linux for decades and still mess up even on prompt so .....
    Imposter syndrome is real tho, I suffered that for a really long time at the start then realized even seasoned engineers make mistakes and have to look things up.
    Thanks for including your mistakes and keeping it real.

  • @kamranabid5557
    @kamranabid5557 4 роки тому

    Thanks for uploading this i have a practical assessment due soon and needed to research and learn how to script in bash! This has been extremely helpful!

  • @jeremyfeather
    @jeremyfeather 6 років тому +10

    Joe thanks so much, this is spot on! Even the mistakes help in the learning process! keep up the great work!!!

  • @johns4195
    @johns4195 6 років тому +12

    you're the man.. thanks mate..

  • @declanmoran1894
    @declanmoran1894 6 років тому +1

    Awesome Joe ! Thanks , I like to see the mechanics of how it all works .

  • @therickestpicklerick
    @therickestpicklerick 2 роки тому +2

    Not lazy... just working efficiently :)

  • @chronosVR.2763
    @chronosVR.2763 2 роки тому

    If you are using the terminal in Ubuntu, you can also use 'gedit' instead of 'nano'.

  • @BumbleBeeTF
    @BumbleBeeTF 2 роки тому +1

    Wow! Thank you! So much great information and you explain it extremely well! Thank You!

  • @Hexbyte965
    @Hexbyte965 6 років тому +1

    Bravo..Bravo...Nice Video Joe. Keep -em coming.

  • @G0USL
    @G0USL 6 років тому +1

    OUTSTANDING video, Cheers, The book is VERY well written. Even I am getting it!! Thanks again

  • @l.elizabethaldana4985
    @l.elizabethaldana4985 4 роки тому +1

    Excellent! easy to understand and follow up; great job!

  • @lovinglife3675
    @lovinglife3675 4 роки тому +1

    Hey Joe , great tutorial mate ... made my life with daily system admin more efficient and effective ..... Thanks again and keep up the great vids.. regards

  • @wisdomchoice2721
    @wisdomchoice2721 2 місяці тому

    Sharp and clear ,Thank you.

  • @CARLOSPH36
    @CARLOSPH36 2 роки тому +1

    Excelente!. Gracias Joe.

  • @rabinotieno6553
    @rabinotieno6553 2 роки тому +1

    the tutorial was enlighting I wanna know more about scripting

  • @nateriver1662
    @nateriver1662 3 роки тому +1

    thank you, man. Love your videos.

  • @gilsantiago3
    @gilsantiago3 3 роки тому

    gracias, English is not my first language and I understood every concept

  • @ZFox57
    @ZFox57 6 років тому +3

    so cool you keep putting out content man keep it up!

  • @georgewinchester6403
    @georgewinchester6403 4 роки тому +1

    Thank you for putting the effort in creating this video, but you have left a fair amount of things unexplained here (for a beginner tutorial of course)

  • @paulstaf
    @paulstaf 2 роки тому

    Using bash scripting, I wrote a whole home alarm system program that uses cheap Chinese sensors to read doors, windows, leaks under sinks, can trigger a relay that sounds a siren, and if someone presses my doorbell, it takes pictures from all my security cameras and emails them to my phone along with SMS messages. All this using BASH scripting on a Raspberry PI.

  • @seansean7653
    @seansean7653 Рік тому

    Any video on how the pipe work?

  • @ronaldallanquilao7689
    @ronaldallanquilao7689 5 років тому +3

    Thank You so much for sharing your knowledge. i find this very helpful

  • @marklambert2777
    @marklambert2777 4 роки тому

    Gosh, "cat

  • @brokebk514
    @brokebk514 2 роки тому +1

    thank you so much joe. this is super helpful!!!

  • @561Aloha
    @561Aloha 2 роки тому +1

    Love this! So helpful

  • @BillFlann9
    @BillFlann9 3 роки тому +1

    Nice Video Joe! Thanks for posting, you're a mensch!

  • @seanparry4048
    @seanparry4048 5 років тому +1

    Very good a great help. Which got me out of Jam ! and resolved a problem for me !

  • @Lyunpaw
    @Lyunpaw 3 роки тому +1

    Wonderful information.

  • @jamesbrinn9701
    @jamesbrinn9701 3 роки тому

    I Miss yiur Linux videos

  • @poparab
    @poparab 3 роки тому

    i have an idea for you,
    Bash scripts they was makes menus for different sigle action with scripting
    File managent. How we scan 2 different folders. Folder 1 is a Storage folder (sample: on the NAS). The other is on PC or workstation. We can synchronize the NAS folder with the Download folder. After that we delete the files in the download folder.
    My abbo is safe

  • @robertcrawford4009
    @robertcrawford4009 6 років тому +1

    Great Video. I have alias that runs the Sudo apt update && Sudo apt dist-upgrade. I named it "updates".

  • @otdefence4169
    @otdefence4169 4 роки тому

    @Joe
    Very good video's you making.
    Nice video and audio quality.
    Nicely done!

  • @Perciwell
    @Perciwell 4 роки тому

    As far as I can figure out currently there is no option "-yy", only the option "-y". I have not found "-yy" in the man pages. But apt does work also correct if you use the option "-y", even if you have written "apt -yyyy install …".
    PS: I'm not sure if "-yy" is an alias for "--force-yes" or was it in former versions of apt-get.
    apt get knows two yes-options: "--allow-yes" and "--force-yes", the second means "yes in every case, and do not ask me", but "--allow-yes" stops the process in some critical cases. You have to read the man pages for exact details.

    • @EzeeLinux
      @EzeeLinux  4 роки тому +1

      It's not in the documentation... I found it on some page about scripting in bash. It originally applies to apt-get. What it does is essentially ask yes to two questions that might be answered when an install is going on. The first is "Do you want to install?" and the second is "Do you really want to install?" I guess... :)

    • @Perciwell
      @Perciwell 4 роки тому

      @@EzeeLinux Ok. Thanks for your answer!
      Honestly I've had a nebulous rememberance, that I might have read and even used this -yy once a long time ago, but I have not found any info about it again in man pages or in the www.
      BTW: I've written a variation of your up script, it's ready. I just have to complete the README files. I've changed many details, and will publish it at my GitHub account by mentioning you and your pages.

  • @gauravrai2736
    @gauravrai2736 Рік тому

    Hi I'm struggling to understand the syntax and elements used in shell scripting. Eg, when to use (()), {{}}, or what is the meaning of the special characters like -z, -n, ! etc. Seems like most expect you to know this already. How do I go about learning this? Is there any book you recommend?

  • @codezero6023
    @codezero6023 6 років тому

    Thanks Joe! Wow, I learned how to do block text without using echo

  • @MonBureauLinux
    @MonBureauLinux 6 років тому +1

    Thanks Joe ! Time to me to create my own bash script :) and bip up for the share

  • @alextlima
    @alextlima 2 роки тому

    I have discovered your Channel few days ago. Congratulations Collins! So I would like to ask you about how can I plan a programm or a script. Is there a method to follow? Other question: do you have suggestions about free labs to practice this knowedge?

    • @EzeeLinux
      @EzeeLinux  2 роки тому

      Here's very good place to start: linuxcommand.org/tlcl.php

  • @Kor1134
    @Kor1134 4 роки тому

    My bash scripting expertise is intermediate at best, but...
    32:00 why not use _getopts_ and a _case_ block (or just a _case_ block) to parse your command line input?
    37:30 putting double quotes around *$@* will break your loop, concatenates each argument into one. (you'll get "file1 file2 file3" instead of "file1" "file2" "file3")

    • @EzeeLinux
      @EzeeLinux  4 роки тому

      That's a lot of extra code to deal with. I keep it simple. :)

    • @Kor1134
      @Kor1134 4 роки тому

      @@EzeeLinux fair enough

  • @txg8878
    @txg8878 6 років тому

    This was a great tutorial! Thanks for posting it. I've been using Linux since 1997 and never really dove into bash, but now I will. Thanks again.

    • @somedude3203
      @somedude3203 6 років тому

      Texas Gambler how did you manage to use Linux for over 20 years but never use Bash? Did you use a different shell?

  • @HazyJ28
    @HazyJ28 Рік тому

    What is the purpose of a sha-bang and why is it necessary when scripting?

  • @VernesMisadventures
    @VernesMisadventures 6 років тому +1

    Great video, Joe! Thanks!

  • @nkushgaur
    @nkushgaur 3 роки тому

    Lovely explanation

  • @eatyourspinachtomperez8700
    @eatyourspinachtomperez8700 2 роки тому +1

    Thank you for this. :)

  • @strato5135
    @strato5135 3 роки тому

    simple... informative... easy.

  • @appalachianpatriot7364
    @appalachianpatriot7364 4 роки тому

    At 18:06, you said "This time I am actually going to put this in my bin folder". What is the reason/ advantage of putting it in the bin folder again? I know you mentioned it earlier in the video, but I didn't understand what you meant. Thanks for the reply!

    • @EzeeLinux
      @EzeeLinux  4 роки тому +1

      The local ~/bin is where you store personal scripts and programs. All you have to do is create it on Ubuntu based systems and it will automatically be added to the path that the system takes to find programs.

  • @yavuzerkal2551
    @yavuzerkal2551 14 днів тому

    amazing video, thanks

  • @shellgenius
    @shellgenius 4 роки тому

    It's be simple to tell anyone can understand thank u for this make video

  • @devondecenzo2658
    @devondecenzo2658 2 роки тому

    Hi on the creating a bin fold in your home dir, is it "touch bin"? Any help on this would be great!!

  • @hippolytus2993
    @hippolytus2993 4 роки тому +1

    Great video!!!!

  • @lightningvini
    @lightningvini 3 роки тому

    Love the video Joe,
    I'm on arch and the bin folder doesn't seem to get detected, what do i have to do? Logging out doesn't work

    • @EzeeLinux
      @EzeeLinux  3 роки тому

      You'll need to add these lines to the end of your .bashrc file:
      # set PATH so it includes user's private bin if it exists
      if [ -d "$HOME/.local/bin" ] ; then
      PATH="$HOME/.local/bin:$PATH"
      fi

  • @ThirdEyeGoat369
    @ThirdEyeGoat369 6 років тому +4

    Thanks for the video!

  • @muhammadseliem2345
    @muhammadseliem2345 4 роки тому +1

    Question, is there a way to run a timed script, like do this after x amount of seconds, or do that after opening this program, or open this prgram.. you know stuff like that

    • @EzeeLinux
      @EzeeLinux  4 роки тому

      You can do all of the above.

    • @muhammadseliem2345
      @muhammadseliem2345 4 роки тому

      @@EzeeLinux no i need thus specific script, run after an x amount of seconds

    • @EzeeLinux
      @EzeeLinux  4 роки тому +1

      @@muhammadseliem2345 look up the sleep command. You can also have things run at specific times with cron or you can have them run daily, weekly or monthly with anacron or systemd timers.

    • @muhammadseliem2345
      @muhammadseliem2345 4 роки тому

      @@EzeeLinux thanks a million

  • @brianhiggins4614
    @brianhiggins4614 2 роки тому

    How did you save the script? ^6:42

  • @Obeeewaan
    @Obeeewaan 5 років тому

    remember that the # on the first line is "special" in that your shell usually looks at it for hints as to how to interpret the script you have told it to execute... it is a pure comment flag elsewhere..

  • @sumitthapa001
    @sumitthapa001 3 роки тому +1

    Very nice tutorial thank you. Thank you for the book recommendation too

  • @amanpandia7912
    @amanpandia7912 Рік тому

    my uptime command is showing me 0 users are logged in, can someone advise me on this, thanks

  • @AfreenKhan-zg4oo
    @AfreenKhan-zg4oo 4 роки тому

    Hi Joe! This is very helpful but I couldn't move the sys-check file to bin. When I put the command it says no-file in directory and also using ls when I check the directory, while all folders appear blue, bin appears green. Is that why this is happening and how can I fix it?

    • @EzeeLinux
      @EzeeLinux  4 роки тому

      I don't have a clue... If you're talking about a bin directory you created in you personal home directory, it may be that it doesn't have the right permissions set. Delete it and try again. If you're talking about bin anywhere else on the system then you need to be careful but use sudo to copy the file there.

  • @fahtfakcarl7695
    @fahtfakcarl7695 4 роки тому +1

    Thank you for this, very informative

  • @ejay4032
    @ejay4032 4 роки тому

    I believe best practises say you use [[ ]] instead of [ ] for conditionals?
    What are your thoughts on this?

    • @EzeeLinux
      @EzeeLinux  4 роки тому

      I don't care as long as it works.

    • @ejay4032
      @ejay4032 4 роки тому

      @@EzeeLinux Awesome, Wahala ti e niyen.

  • @soccerfan5908
    @soccerfan5908 2 роки тому

    Does somebody get "no command found " when trying to run the file(sys-check)? Despite doing the exact same steps as the video.

    • @EzeeLinux
      @EzeeLinux  2 роки тому +1

      Make sure the file has permissions set to be executable. If it's not in a place where the system normally looks for executable files run it with ./ in front of it to tell the system where it is.

  • @Uneke
    @Uneke 4 роки тому

    An update -yy is fine but a distro upgrade isn’t. Lots of programs and setting can be scrapped or replaced doing that

    • @EzeeLinux
      @EzeeLinux  4 роки тому

      Done it for years. No problems. The default settings in Ubuntu now favor automated upgrades. The devs are careful not to break anything... :)

    • @Uneke
      @Uneke 4 роки тому

      Joe Collins I used to run Ubuntu (now Kali) I remember once I did an auto dist upgrade and lost my nvidia driver settings (I wanted better hashcat speeds and nuveau offers crap cuda). It switched back to nuveau but was conflicting and I ended up with a blank screen. I had to tty to blacklist the nuveau. Was a massive headache lol

  • @talzO9
    @talzO9 4 роки тому

    when i run free it says command not found :( also the -h for du doesn't seem to work as I get a long list that is definitely not what you got

  • @uniquechannelnames
    @uniquechannelnames 3 роки тому

    Just wondering if writing a script, is each seperate line treated as if there's a "&&" or ";' command between each line?
    IOW does a command need to execute seccessfully for the next to execute? If an 'apt update' cmd fails for some reason, will the 'apt upgrade' cmd after it not go forward/will the script stop?

    • @EzeeLinux
      @EzeeLinux  3 роки тому

      It depends on the way you write the script. There are several ways to test for the exit status of any command and then figure out what to do whether it was successful or not. :)

  • @engelberthk
    @engelberthk 6 років тому

    Where should I place the script? I got error : bad interpreter: No such file or directory, any realtion to path or rights. I have done the chmod +x command. Thanks

    • @EzeeLinux
      @EzeeLinux  6 років тому

      Make sure you have #!/bin/bash at the beginning of the script. The shell can;'t figure out what to do with your for some reason. You can place a script in /home/username/bin or home/username/.local/bin or /usr/local/bin if you want everyone who sues the computer to have access to it. :}

  • @arindamnag2484
    @arindamnag2484 3 роки тому

    There are a few revelations i have discovered on Ubuntu
    Shebang line is not necessary to execute a shell script
    Even a script written in ".txt" format can be executed using Bash command, doesn't have to be a .sh or .bash format.

  • @henrymach
    @henrymach 6 років тому +3

    Is there a special reason why you use apt-get instead of apt?

    • @EzeeLinux
      @EzeeLinux  6 років тому +3

      It has more options and is more script friendly because there is no progress bar. :)

    • @cthedosboss5113
      @cthedosboss5113 6 років тому

      apt-get gets all of the dependencies i think

  • @refaiabdeen5943
    @refaiabdeen5943 4 роки тому +1

    Cheers Mate! Much appreciated.

  • @JeffM---
    @JeffM--- 6 років тому +1

    Thanks man, great video!