Learn how to write Bash scripts [Full Guide]


shebang_250px after a while, by dint of repeat 10 times, 100 times the same things, the ‘normal’ computer scientist (what is being normal?) is the question of the automation of the tasks to be performed.
Certainly he heard talk about script & even of Bash but finally how it works? How to write a script that would do the job instead of me?
Write a script is already a job! But like any good computer scientist is a ‘good’ Slacker (in the sense or he prefers to be the machine that works in its place 🙂), arrive on the day where he decides to go & to write my first script.


paresseux_600px


why?


bin-bash the origin of the scripts is in laziness of computer scientists, some commands bash being difficult to design & long to write, it was desirable to save them for the re – run, with the same or different values.


the author form higher technicians in computer networks & telecommunications (TSRIT). Reducing the time devoted to Linux in this training, the time devoted to the practice of scripts, more and more requested by company & the request of trainees of a clear & accurate support led him to write this book.


anita-hart_cc-by-sa


this course/TP is a rewrite, adaptation & an extension of two articles Tristan COLOMBO in Linux practice special n ° 20 , first step in shell script & shell scripting advanced concepts . Indeed, the author was firstly submitted to the constraint section of magazine & on the other hand, a different issue of the public.


bash


if remarkable that these two texts are, they had to be adapted to the training. I.e. on the one hand, to people who have never programmed & on the other hand, seeking to optimize the use of servers & working & not to write software. However the essential has been kept.


for whom?


this booklet is intended to serve as additional support to apprentices Linux network administrators, to wrestle with system administration scripts.


tux_600px
all the individuals who participated in Linux for more than 100 hours should be able to do the exercises, devoting between 16 & 40 hours of work (bin so it can’t do it on your behalf, there is no magic formula: you have to work a little bit 😀).


who’s the author?


photo_michel Michel SCIFO was born in Arles, there is a little more than half a century. Since 1999, he lives in Grenoble.
Grandson of a naturalized Italian Pedlar, a provencal roadman & their respective wives, comedian patented, an economist by training he also studied the basics of law, sociology, social psychology and the psychology of work. He is a consulting engineer. It forms the senior technicians in computer networks to the Association of professional training of adults (it’s a colleague 🙂).
Great reader, he started writing in 2001. He wanted to write my ideas to avoid duplication; on the other hand, having a spirit of contradiction exacerbated, defending, according to the earlier ideas of right, sometimes ideas left 🙂, he felt the need to do
point on my own. There were two books for my loved ones, available on its website www.scifo.fr (in the topic: books ), & addicted to writing.


esperluette_min he is president of the ARDOUR (Association pour la Réhabilitation De l’Esperluette Uniformément Répartie). He uses this symbol, noted ‘&’ to replace the conjunction “and.” that’s why you have seen the ampersand on many occasions since the beginning of the article!


well, we talk about the book?


that is, Yes, I do.


couverture


Michel wrote this booklet destined for beginners in bash script. He talks to start the woes of a computer scientist (not) face (e) each morning in the preparation of the essential coffee that starts my day.


grognon_matin


our it guy (don’t) lazy as he has, is told he should automate this repetitive task. He imagines a robot in charge of these operations recurrent (Nothing) to do with powder.


gaston_600px


but beyond this innovation comes to tell the robot what to do! It’s time for Michael to introduce the concepts of analysis and programming, level of programming. Once the algorithm (in written french sense), it will translate it into one of the existing programming languages.


baille


This allowed him to introduce in a humorous way of notions such as instructions, functions, operators, variables and other constants. I have found the methods used in training of adults from concrete examples allowing to assimilate concepts in lez bringing things of everyday life.


and after?


then we move to the concrete, scripting with Vim and Geany (like Geany is installed original in the latest versions of Raspbian JEssie).


we will begin with a “Hello world” Gallic sauce, by writing “Hello” on the screen from a script.


carotte of course, if one could write that scripts of this kind, it would present no interest, but to produce more complex, to introduce two important notions: that of data & control structure.
When you cook, even if you are ‘multi-tasking’, you try to perform each instruction one after the other in sequence. Yet, certain actions result in a break in sequence: you can’t move to the next line as long as you have not completed the current action. So when you cut a carrot in Puck, you make a iteration to cut a slice of carrot, until there are more carrot chopping.


you discover, always in a concrete way, the control structures that allow to organize the execution of the instructions or by choosing some & not others either by repeating some or a combination of both of these…


the exercises


exercices


do not be frightened by this illustration of 😀 you will find a series of progressive exercises (simple and complex). If you really want to learn how to write scripts, I advise you to do them alone (with the help of the doc anyway). Do not have a ready-made solution, you won’t learn anything.


avoid recover ready-made scripts, because the only way to understand a language is to practice, not to use scripts done by others, as people think.” You will never learn English using the services of an interpreter! “said Michel in my presentation of the exercises.


bash-logo-web to succeed these scripts, you must define what you want to do, then pick up with orders apropos & man external & internal controls & their options, necessary to the achievement of the outcome. Computer it’s called RTFM 😉


and as in TV magazines, the answer to games found in the last pages.


reponse


scripts proposed in response has been made by an intern in the two days scheduled for the realization of this sequence. These are not the fastest or shortest, however they are worthy of an experienced UNIX user & they work! Michel then added comments critical or explanatory & fixed alternative. So you should be able to verify your achievements, knowing that there’s never a solution but more or less effective, fast, comprehensible solutions…


with this 260 page book you have a springboard to explore the world of scripts. Take your time and do by yourself, it’s the only way to learn and grow. Michel has published this book in PDF (Depot legal 1st quarter 2015 – ISBN: 978-9537431-5-9 © the master Refleur 2013-2015) in NC-BY-ND-SA (no commercial use, NC – – paternity, BY – no derivative works, ND shares the same, SA). You can then copy it back and broadcast without breaking the licence, provided you do not sell (alone or combined with another product) and quote its author.


A note in the same style a book on PHP-MySQL, to explore if you want to venture on this ground…


to download two books (free) click on the links below. The download button is at the bottom of the page.


download: with the Bash shell scripts


download: Initiation MySQL & PHP


binbash-sh-600x600


my sites





No comments:

Powered by Blogger.