Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Do I need to learn bash scripting?
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Do I need to learn bash scripting?

dnomdnom Member
edited May 2012 in General

I know the basics already and I know python quite well. Whenever I needed a script that is a bit complex, I write it in python so I never had the chance to learn it deeply.
I think most sysadmins are well versed in bash. But is it really a must? Is there a huge advantage of learning it aside from a few mb that I would save for not running the python interpreter?

Comments

  • vps6netvps6net Member

    If you already have advanced knowledge of python, I wouldn't say it's a must, however bash scripting is definitely an invaluable skill. To me it has always been something picked up as-needed over time, rather than something I committed to practicing.

  • Learn it as you need to learn it.

  • @dnom said: I know python quite well.

    Then bash scripting isn't hard to pick up on at all.

    @Daniel said: Learn it as you need to learn it.

    +1. No need to go through a "bash for dummies" book cover-to-cover ;)

  • KuJoeKuJoe Member, Host Rep

    Do you need to learn it? No. Should you learn it? Yes. Bash scripting makes a server admin's job easier. Plus, if you already know Python you'll pick it up quickly. As others have said, I learn it as I need to but am so glad I did.

  • GaryGary Member

    There's so much out there on the web in terms of tutorials, forum Q/A etc, that 99% of any problems you'll encounter have been solved already.

    Your coding background will mean that anything not already explained on the web will be fairly easy for you to solve anyway.

    It's astounding what can be achieved by a chain of pipes :)

    Don't sit down and try to learn bash scripting, just pick up bits here and there as you encounter problems you need to overcome.

  • yomeroyomero Member

    @Gary said: Don't sit down and try to learn bash scripting, just pick up bits here and there as you encounter problems you need to overcome.

    This.
    Otherwise, is annoying and boring lol

  • raindog308raindog308 Administrator, Veteran

    Sysadmins should know bash or ksh. That's what all the startup scripts, etc. are written in.

    And you spend a lot of time in the shell - why wouldn't you want to know every shortcut, trick, and speedup to save you time? Learning bash is just learning the shell, which is your basic tool. Don't think of "learning bash" as just "writing scripts" - you also learn the language so you can do quick "for file in ls *.log ; do something ; done" stuff while in the shell.

    Thanked by 1dnom
  • KuJoeKuJoe Member, Host Rep

    As somebody on here put it a long time ago (forget who it was), a good admin can ninja the CLI. On a semi-different subject, does anybody else enable logs in their SSH app (i.e. PuTTY)? I just noticed that I spend entirely to much time in SSH when I compressed 7GB of SSH logs into 600MB. LoL

  • CoreyCorey Member

    Learn it when you need it, much like everyone else said.

  • I've been learning some bash. It's useful for writing batch scripts to automate a bunch of commands you do over and over, but as a programming language it sucks. You're better off with Python (especially since it can do virtually everything bash can do with the os and commands modules).

    Let me give you an example. The other day I was doing some data processing. I wanted to get an email when it finished and figured the best way to do that (after the processing had started) was to write a script to grab the 5 min load avg and send an email when it dropped below some value. I thought this was a good opportunity to learn some more bash. I used a combination of awk and sed to grab the number from uptime and assign it to a variable, but I couldn't get the if statement to work. Turns out bash doesn't understand floats, only integers! (There are some hackish ways around this, but I prefer Python's cleanness and elegance.) After half an hour of fooling with this bash script, I wrote a Python script in a couple of minutes:

    import os, smtplib
    load = os.getloadavg()[0]
    if load < 1.0:
    ...

    Done and done.

  • dnomdnom Member

    @everyone said: Learn as needed.

    @yomero said: Otherwise, is annoying and boring lol

    I agree. That's why I'm trying to find cases in which I kinda 'need'
    to learn and use bash.

    @raindog308 said: Don't think of "learning bash" as just "writing scripts" - you also learn the language so you can do quick "for file in ls *.log ; do something ; done" stuff while in the shell.

    So I think I'll be learning it this way. since for writing complex script:

    @BuzzPoet said: You're better off with Python (especially since it can do virtually everything bash can do with the os and commands modules).

    There's still this part of me telling myself "Awk is cool, you should learn that!", "You should have written that script in sh!" But my laziness wins :)

  • Learning bash is a bit like learning vi, you only need to know the bits that get you by. I've been bourne shell scripting (in vi) for 20 years but don't know everything about the bourne shell and know very little about the capabilities of vi, but I can get by.
    The problem is not all systems (firewall appliances especially) will have python installed (and definately not emacs), so it's worth knowing enough to get by.

  • 1q11q1 Member

    You don't have to. I think python can do all of bash's jobs.

  • bash scripting I've found more useful when it's a bunch of commands that need to be run. For example a script that sets up a new vps and you want to run a bunch of commands. Python is good for when you need to do a lot of processing of data instead of just running them. Also an issue you have to deal with for python is version incompatibilities. Generally you can assume at least 2.5 but for example centos 5 runs python 2.4... yeah.

Sign In or Register to comment.