Shell scripting! Where to start?

MicroScoMicroSco Posts: 18Member ■■□□□□□□□□
Passed Linux+ two months ago. Now trying to learn some scripting stuffs.

Can anyone suggest me where to start/proceed? I know the best way to learn is to do the things in a production environment but that option just aint available to me at the moment. So, Just want to know enough so that I can add that skill into my resume.

Any book/links/suggestions?

Comments

  • DoubleNNsDoubleNNs Posts: 2,013Member ■■■■■□□□□□
    1st: The Linux Command Line by William E. Shotts, Jr.
    2nd: Unix Shell Programming (3rd Edition): Stephen G. Kochan, Patrick Wood: 9780672324901: Amazon.com: Books

    (At least that's what I did. You might be able to find a better 2nd book like "Linux Command Line and Shell Scripting Bible" or even "Classic Shell Scripting" but I've never read either of those so I personally can't recommend)

    Try to have goals, such as small scripts or things to automate in while you're learning.

    I learned shell scripting because I realized at work I had to type $(command1) and copy and paste a part of the output into $(command2). I thought to make a script to combine the two steps so I only had to call 1 script. The result took me almost the entirety of the 1st book (2 weeks) and ended up being the ugliest 2-line script in the world. But it worked. From there I just kept making more scripts, each one slightly larger and/or more sophisticated than the last.

    I'm by no means a programmer/developer. But I've been a better shell scripter than almost all my fellow operations co-workers from those 2 books alone.

    If you've passed the Linux+ it'll probably be a pretty painless journey for you. You'll just need to learn some very, very basic sed+awk, some cut, tr, grep, loops, command substitution, input redirection, etc. If you already know the difference between a for loop and a while loop, you're pretty much there already.
    Goals for 2018:
    Certs: RHCSA, LFCS: Ubuntu, CNCF CKA, CNCF CKAD | AWS Certified DevOps Engineer, AWS Solutions Architect Pro, AWS Certified Security Specialist, GCP Professional Cloud Architect
    Learn: Terraform, Kubernetes, Prometheus & Golang | Improve: Docker, Python Programming
    To-do | In Progress | Completed
  • varelgvarelg Posts: 790Banned
    Search for bash scripting guides (beginner's and advanced) on tldp.org and start from there.
    You could first learn how to declare variables and put them through conditionals.
    I am posioning the forums.
  • clarsonclarson Posts: 897Member ■■■■□□□□□□
    I know the best way to learn is to do the things in a production environment

    no, no, no, no. Your production environment isn't for learning. You do your learning in an environment where you can make plenty of mistakes (because you will). We test the scripts that are run in production not only to make sure they work properly, but to also avoid unintended consequences.
  • DoubleNNsDoubleNNs Posts: 2,013Member ■■■■■□□□□□
    He probably meant "learn by doing at work." You can swap out "production" w/ "professional."
    Goals for 2018:
    Certs: RHCSA, LFCS: Ubuntu, CNCF CKA, CNCF CKAD | AWS Certified DevOps Engineer, AWS Solutions Architect Pro, AWS Certified Security Specialist, GCP Professional Cloud Architect
    Learn: Terraform, Kubernetes, Prometheus & Golang | Improve: Docker, Python Programming
    To-do | In Progress | Completed
  • MicroScoMicroSco Posts: 18Member ■■□□□□□□□□
    @DoubleNNs - Thanks

    @Clarson- I actually meant learning and gaining experience by doing it in real. Thanks.
  • vanillagorilla3vanillagorilla3 Member Posts: 79Member ■■■□□□□□□□
    Just my two cents and something I heard from other Linux admins, I would learn Python instead of Bash scripting. I feel like it would be more valuable especially since it works on multiple OSes.
  • VeritiesVerities Posts: 1,162Member
    The Linux Bible is an easy to read book thats made for beginners:

    http://www.amazon.com/Linux-Bible-Christopher-Negus/dp/1118999878/ref=sr_1_1?ie=UTF8&qid=1461254318&sr=8-1&keywords=the+linux+bible

    If you want to start with a free resource:

    BASH Programming - Introduction HOW-TO

    BASH scripting is very effective, but once you've been writing those scripts for a while you'll want to move on to a programming language to maximize the benefits of automation.
  • indigomx9indigomx9 Posts: 32Member ■■□□□□□□□□
    Andrew the Urban Penguin has a great section on BASH Shell Scripting. icon_cool.gif
    Bash Scripting
  • JoJoCal19JoJoCal19 California Kid Posts: 2,801Mod Mod
    Verities wrote: »
    The Linux Bible is an easy to read book thats made for beginners:

    Linux Bible: Christopher Negus: 9781118999875: Amazon.com: Books

    I second this book. I have it and it's an awesome text.
    Have: CISSP, CISM, CISA, CRISC, eJPT, GCIA, GSEC, CCSP, CCSK, AWS CSAA, AWS CCP, CEHv8, CHFIv8, ITIL-F, MS Cyber Security - USF, BSBA - UF, MSISA - WGU
    Currently Working On: Python, OSCP Prep
    Next Up:​ OSCP
    Studying:​ Code Academy (Python), Bash Scripting, Virtual Hacking Lab Coursework
  • Muhammed HMuhammed H Posts: 93Member ■■■□□□□□□□
    I think the best way to learn scripting is by doing it. Start with writing a number of commands and save them as a script and run it. Then slowly try to manipulate the results of the commands.
  • Kinet1cKinet1c Posts: 604Member ■■■□□□□□□□
    I've been slowly working my way through "How Linux Works" and also have The Linux Command Line (as mentioned by DoubleNNs) lying in wait. HLW goes very in depth but it does tell you to skip ahead if you're new or have no interest on certain topics. I'd also recommend picking up the <insert topic> pocket hand books to have for quick reference, they're pretty useful to keep on your desk in work or at home.
    2018 Goals - Learn all the Hashicorp products

    Luck is what happens when preparation meets opportunity
  • ally_ukally_uk Posts: 1,146Member ■■■■□□□□□□
    This:

    https://www.amazon.co.uk/Linux-Command-Shell-Scripting-Bible/dp/111898384X/ref=sr_1_1?ie=UTF8&qid=1461867433&sr=8-1&keywords=linux+shell+bible

    Plus here is a whole series

    https://www.youtube.com/watch?v=nVt3Rst-2H8&list=PL7B7FA4E693D8E790


    lastly start with a simple project set a goal i.e I want to be able to backup a specific directory automatically. Get the basics laid out then take it a step forward add user interaction, then create a nice menu system with advanced features. next add the option to email the root account once backup is complete.

    Create scenarios like the above and play :)
    Microsoft's strategy to conquer the I.T industry

    " Embrace, evolve, extinguish "
  • Kinet1cKinet1c Posts: 604Member ■■■□□□□□□□
    Just wanted to come back to this post. I started reading The Linux Command Line and if you are completely new to Linux then this is the book for you. In the 6 chapters I've read, it's filling in some small gaps in my knowledge but it would be a great place for a newbie to start. I'm a little further on in "How Linux Works" and it does dive deep in to how it works but if you're looking for how to get stuff done then I'd opt for The Linux Command Line.
    2018 Goals - Learn all the Hashicorp products

    Luck is what happens when preparation meets opportunity
  • VeritiesVerities Posts: 1,162Member
    Kinet1c wrote: »
    Just wanted to come back to this post. I started reading The Linux Command Line and if you are completely new to Linux then this is the book for you. In the 6 chapters I've read, it's filling in some small gaps in my knowledge but it would be a great place for a newbie to start. I'm a little further on in "How Linux Works" and it does dive deep in to how it works but if you're looking for how to get stuff done then I'd opt for The Linux Command Line.

    Glad to hear you're progressing well. If you have any questions or need any additional resources, just let us know.
  • blargoeblargoe Self-Described Huguenot NC, USAPosts: 4,171Member ■■■■■■■■■□
    I am currently working on the same thing since finishing up Linux+. Here is my take:

    There are a number of resources all over the internet, paid or not, that will help you learn bash. If you are like me, and have other scripting experience (I see you are MS and VMware certified, so perhaps you are comfortable with Powershell for example), then the learning curve isn't steep if you have very much familiarity with Linux.

    Personally, I have gone through some of the basic syntax type things... single quotes vs double quotes vs tick marks, variable expansion, etc; noting the difference between bash and powershell. Then move on to conditional operations and loops and functions and do the same thing. I have **** sheets hanging at my desk that I have downloaded from various sources to help me if I forget the proper syntax (needing this less and less now) for a specific operation.

    Finally, I being solving relevant problems with simple bash scripts. My project today is to remove the entries for a bunch of detached devices on 14 ESXi hosts that have been permanently deleted from the SAN. After about 30-45 minutes, I had a working script on my vMA VM that iterated through my list of hosts, targeted the host, parsed the output of an esxcli command to produce a list of permanently detached devices, and ran other familiar esxcli commands to do the rest of the work for me.

    Much better than running the same command 476 times.
    IT guy since 12/00

    Recent: 11/2019 - RHCSA (RHEL 7); 2/2019 - Updated VCP to 6.5 (just a few days before VMware discontinued the re-cert policy...)
    Working on: RHCE/Ansible
    Future: Probably continued Red Hat Immersion, Possibly VCAP Design, or maybe a completely different path. Depends on job demands...
Sign In or Register to comment.