Options

Bash Scripting

ally_ukally_uk Member Posts: 1,145 ■■■■□□□□□□
Hey guys I am interested in learning how to learn Bash scripting the problem is I am not a programmer and havent got a clue about programming concepts.
So how does a noob get into this? currently I can write real basic scripts that declare variables and echo words to the prompt and other noob stuff such as
chaining commands together.

Am I missing something here? please don't say a brain :0 documentation aimed at a apparent noob goes over my head! it's like the person writing it doesn't understand
that ive never programmed in my life so they get you to start off with a classic hello world script then it's onto command operations, postions, loops and i'm like wtf!!!!!!

Is there a guide out there that actually gets you to create scripts gradually / Holds your hand?

I'm starting to get frustrated and disheartened I have a strong desire to learn this like a overwhelming urge but I can't seem to get off the ground icon_sad.gif

How did you tackle this?
Microsoft's strategy to conquer the I.T industry

" Embrace, evolve, extinguish "

Comments

  • Options
    alxxalxx Member Posts: 755
    practise, read examples and slowly build up the complexity of your scripts step by step.
    practise , practise, practise

    start here
    BASH Programming - Introduction HOW-TO: Very simple Scripts

    hows your linux/unix knowlegde ?

    If not so good learn all the usual linux/unix commands as you will need them with bash
    Commonly used Unix commands
    Using UNIX commands

    other tutorials
    Bash scripting Tutorial
    Bash Guide for Beginners
    Goals CCNA by dec 2013, CCNP by end of 2014
  • Options
    prampram Member Posts: 171
    I'd learn another procedural language like Python or Perl first. Theres simply more learning material for those, and everything you learn you will be able to apply to bash scripting.
  • Options
    Master Of PuppetsMaster Of Puppets Member Posts: 1,210
    Great resources by alxx. I'd just like to add that it will be a good idea for you to start with The Linux Command Line - The Linux Command Line by William E. Shotts, Jr. . After that the Bash guide for beginners will come easier. Also, there is a great tutorial on bash scripts here LinuxCommand.org: Writing shell scripts.
    Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for.
  • Options
    devils_haircutdevils_haircut Member Posts: 284 ■■■□□□□□□□
    Here's a couple of links that I have bookmarked that might be useful for learning more about bash scripting:

    BASH Programming - Introduction HOW-TO

    http://rute.2038bug.com/index.html.gz (this is more of a Linux tutorial, but it contains a simple section on bash scripting)
  • Options
    ally_ukally_uk Member Posts: 1,145 ■■■■□□□□□□
    Thanks people very informative, To answer the question to what my current Linux Knowledge is like

    Feel Comfortable using BASH, And using Utilities like Grep, Piping commands. directory navigation,
    Vim is the editor I am most comfortable with.
    I understand how to setup a Alias, Variables, How to customize PS1 to make changes to your shell

    All that is fine but when I am faced with unknown unfamiliar territory such as

    Exit Codes, Command Operators, Flow Control, Loops, Functions, Command Substitution,

    That's when the s**t hits the fan!
    Microsoft's strategy to conquer the I.T industry

    " Embrace, evolve, extinguish "
  • Options
    The TechnomancerThe Technomancer Member Posts: 96 ■■□□□□□□□□
    Exit codes:

    0 means everything went all right. Anything else means something went wrong. You can use error codes in scripts you write to determine where the process broke in your script, and you can exit with a status code using "exit" followed by the number you want to use.

    Redirection pipes and such allow you to feed output into another file or command, or feed input to the original command.

    I went over loops in my "ask me anything" thread.

    Don't worry about functions for now. You'll know when you need them.

    Command substitution lets you set a variable based on the output of another command, or run a loop using the output of a command as the parameters.

    Like, let's say I have a nighly rsync job that syncs logs somewhere, and the folder is based on the date in YYYYMMDD format, and runs for yesterday's logs.

    So, in my script, to make sure that the date is always correct (according to the server, anyway) without me having to manually enter a date as an argument, I can do:
    DATE=$(date --date='yesterday' +%Y%m%d)
    

    People will also use backticks rather than using the subshell method. In most cases, they're functionally equivalent:
    DATE=`date --date='yesterday' +%Y%m%d`
    

    Subshells do have one clear use case where they are more efficient than backtick substitution, though:

    To save the contents of a file in a variable with backticks:
    var=`cat somefile.txt`
    

    To do the same with a subshell:
    var=$(<somefile.txt)
    

    You're using BASH's builtin redirection now rather than spinning up the cat process, with is slightly faster.
    Any sufficiently advanced technology is indistinguishable from magic.
  • Options
    BryzeyBryzey Member Posts: 260
    I just purchased on Udemy a bash introduction video course and a Python for beginners course. They have a black Friday sale at the moment.

    Using BLACKFRIDAY13 coupon code I got the Python for $24 reduced from $99 and I got the bash scripting for $7 reduced from $25. Not sure if the coupon code works for everyone or if it was specific to me but even at $24 it is still a pretty good price for an intro to bash scripting.

    I can't comment on quality yet as I don't plan to start them until after I finish my LPIC-1 but for such a small price it might be worth a try.
  • Options
    qwertyiopqwertyiop Member Posts: 725 ■■■□□□□□□□
    Honestly it comes down to practice. I'm not a programmer either but ive dabbled in some small Batch scripts in my early days and started out by translating what I already knew to Bash and quickly went on from their as by that point I was more than used to its basic syntax..
Sign In or Register to comment.