Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Shell Scripting

  1. #1
    Join Date
    Apr 2007
    Beans
    74

    Shell Scripting

    Hi guys I have developed a interest in Linux and Open Source Technologies I wish to develop my skills further and to become more productive in my spare time and actually learn some stuff.

    I am pretty comfortable using the command line and am willing to get my hands dirty. The first area of interest is Shell Scripting, Now I am not a programmer I don't think like a programmer or have the programmers godlike mentality Variables? For? Loops? it currently all goes over my head

    So for somebody who knows nothing about scripting or programming concepts how do you begin to learn to script? am I out of my depth here? is there a suitable beginners course or tutorial or book out there? which starts you off with the basics i.e hello world and takes it a step further with introduction of variables etc.


    How did you guys start with Linux? what kind of projects did you start with and how much time do you need to dedicate to it to develop a solid understanding.

    Thanks for the help appreciate the insight

  2. #2
    Join Date
    Apr 2008
    Location
    LOCATION=/dev/random
    Beans
    5,767
    Distro
    Ubuntu Development Release

    Re: Shell Scripting

    Check out the Ubuntu wiki, specifically the links on this page...

    https://help.ubuntu.com/community/CommandLineResources
    Cheesemill

  3. #3
    prodigy_ is offline May the Ubuntu Be With You!
    Join Date
    Mar 2008
    Beans
    1,219

    Re: Shell Scripting

    Well, I learned bash when I was creating a script that would install and auto-configure xl2tpd (my ISP uses L2TP for user auth). Initially I wrote a small script but eventually it grew to over 1k lines and at some point the project became too time consuming for me to maintain. My code was really naive and quite ugly but it worked. :)

    You don't need programmer's mentality but you still need to think before and while writing any piece of code. If it feels wrong and clumsy, it probably is. Sometimes perfection isn't worth it but often better algorithm is also shorter and clearer. So learn your tools - use control flow statements (for/while, if, case) whenever possible. Split any complex problem into smaller problems and solve them one by one. Read man pages, use Google and don't be afraid to ask for help.

  4. #4
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Shell Scripting

    I started out the same ay prodigy_ did. I think my first shell script was one to handle daily backups and it was a mess at first but kept getting refined as time went on. I eventually wrote up a virtualbox startup script to gracefully shutdown/startup any VMs that were running and now I think vbox has one of those scrips builtin now.

    One thing that has been invaluable to me is testing my scripts on a test box.... don't run anything on production unless you want a lot of pain and tears.
    Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide

    Tomorrow's an illusion and yesterday's a dream, today is a solution...

  5. #5
    Join Date
    Feb 2009
    Beans
    98
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Shell Scripting

    These days, google is your best bet in learning shell programming for free.

    The basic shell programming examples dating back from year 2000 from the tldp.org in one of the google search results is still very much accurate even to this day. The logic operators has not changed much, if at all.
    Overclocked HPML150 running Precise Pangolin 12.04 LTS

  6. #6
    Join Date
    Jan 2010
    Location
    Germany
    Beans
    165
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Shell Scripting

    Hi ally_uk,

    You have chosen a great subject and one that is very close to my heart. I certainly commend you for wanting to have a dabble at shell scripting. So here is my two cents:

    Before you think about shell scripting I always found the following questions helpful when evaluating my expectations:

    1. What do you expect to get out of it?
    2. What do you think it will do for you?
    3. Do I have enough base knowledge to understand the scripting elements?

    So, for question one. Shell scripting is fairly lightweight and in my opinion there is a real for that. It won't do everything, it's not a programming language and as such it has limitations. Have you ever thought about Python?

    For question two, this is quite fundamental in itself really because there and tonnes of things you need to know about the system you want your script to work on. For example; a shell script that works on Ubuntu may not necessarily work on Arch Linux and vice versa. This is no way to put you off, just an attempt to get your mind going. As it was suggested above "Google" has a lot of search returns regarding the subject and its for that reason people don't really need any knowledge because you can just cut and paste things and hope it works.

    It is very important to understand the pseudocode basics though for example:

    What will the command "echo" do for you or " echo -e "This is my text" "

    "IF" statements and "while loops" are your friend. They will help you with an endless list of options in order to make your scripting as interactive as possible for the end user.

    Most programmers and I include myself this this example, sit down with some paper and sketch out the base structure of what we want to achieve. The we start punching out the keys in front of the monitor.

    Good luck by the way and feel free to ask more questions, though I think we may be abusing shell scripting in this section of the forum as technically it's not just for server platforms.
    Try not to be a man of success but be a man of value
    USE FUL LINKS
    Ubuntu Server setup guide
    setting up a DNS Server on Ubuntu

  7. #7
    Join Date
    Apr 2007
    Beans
    74

    Re: Shell Scripting

    Thanks for the replies I basically want to learn how to automate some administration tasks, such as backups, creating users, package updating script. Plus the learning about essentially the basics to build a solid foundation once I have become comfortable I will learn Python. You wrote over 1000 lines of code? I can write two lines

  8. #8

    Re: Shell Scripting

    Quote Originally Posted by ally_uk View Post
    You wrote over 1000 lines of code? I can write two lines

    lol, they all start with two lines and grow and grow!

    I'd recommend setting up a github repository and storing your scripts there, that way you can edit them and keep them for longer and move the scripts to new machines easily
    please check out my blog I have a linux tips section

  9. #9
    Join Date
    Apr 2007
    Beans
    74

    Re: Shell Scripting

    Hehe so what resources did you use to learn to write over 1000 lines of code right now I am struggling to get off the mark

  10. #10
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Shell Scripting

    Quote Originally Posted by localhost8080 View Post
    lol, they all start with two lines and grow and grow!
    Ain't that the truth. I've got a simple vbox script i wrote to power down the VMs before the system rebooted and that went from simple and a monster.

    Quote Originally Posted by ally_uk View Post
    Hehe so what resources did you use to learn to write over 1000 lines of code right now I am struggling to get off the mark
    All it takes is practice. Depending on the language, of course.

    This one is pretty cool

    http://www.learnpython.org/
    Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide

    Tomorrow's an illusion and yesterday's a dream, today is a solution...

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •