From owner-freebsd-questions@FreeBSD.ORG Tue Jul 26 23:53:52 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4A7AF1065677 for ; Tue, 26 Jul 2011 23:53:52 +0000 (UTC) (envelope-from jherman@dichotomia.fr) Received: from mail.dichotomia.fr (hydrogen.dichotomia.net [91.121.82.228]) by mx1.freebsd.org (Postfix) with ESMTP id D10EA8FC13 for ; Tue, 26 Jul 2011 23:53:51 +0000 (UTC) Received: from [192.168.1.18] (unknown [178.33.164.134]) (Authenticated sender: kha@dichotomia.fr) by sslmail.dichotomia.fr (Postfix) with ESMTPSA id CD71A3DD06F for ; Wed, 27 Jul 2011 01:50:40 +0200 (CEST) Message-ID: <4E2F53A7.3040906@dichotomia.fr> Date: Wed, 27 Jul 2011 01:54:15 +0200 From: Jerome Herman User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 To: freebsd-questions@freebsd.org References: <4E2F1C0F.4040108@msen.com> In-Reply-To: <4E2F1C0F.4040108@msen.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (sslmail.dichotomia.fr); Wed, 27 Jul 2011 01:50:41 +0200 (CEST) Subject: Re: Book recommendations (slightly OT) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Jul 2011 23:53:52 -0000 On 26/07/2011 21:57, Mark Moellering wrote: > I want to automate some tasks, creating directories, file editing, > etc. I was going to pick up a book on shell scripting but wanted to > ask the list if; > A) I am barking up the wrong tree and should use something else. > B) If I am headed in the right direction, what is the best book / > resource to use? > > Thanks in advance > > Mark Moellering > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to > "freebsd-questions-unsubscribe@freebsd.org" The first thing to do is to define what you want to do with scripting. Most users have now turned to bash, very easy and quite powerful, though it has some specifics you won't find in any other shell. Such as replacing certain simple commands on the shell line by its own internal version, which can be very frustrating. This said it is probably the easiest shell to learn given there are lots and lots of examples, tutorial and users around here. For pure Unix/BSD/Solaris... professional administration, you have to learn tcsh/csh (basically the same thing, tcsh being an improved version). Basically it is a bit like vi. Even if you do not like vi, but want to professionally maintain Unix/BSD/Solaris..., you have to learn it, because one day you will have to log on an old server and vi will be the only "modern" editor available. Csh/Tcsh will basically be installed on pretty much every computer you might find. And csh can be tricky at time if you only know Bash. On the other hand if you are a user/dev just wanting to automate some of his daily routine, then you can go for pretty much any shell you want. I personally prefer zsh. One shell that is great but you need to be aware of is ksh. The problem of ksh is that it is so different from every other shell that learning it is a bit of a trouble. It is hard to find good example, and it is hard to transcribe ksh scripts and logic unto an other shell. I can only advise you to browse around, look at what every shell has to offer and pick one. Do not hesitate to change if you are not happy. As far as learning a shell goes, well it is more about going for net tutorials and reading man pages over and over again. At first you will be using "cat", "|" and ">" a lot. That is normal, but the only way to progress is to try to use them all as little as possible. (Which generally translates into reading the man page again). Last thing, though it is considered to be a "welcome ritual" among admins, do backups, lots of backups, and test your scripts with another account that cannot destroy all your files at once. When learning to script you will one day make a stupid mistake, it will be a very simple script and a very stupid mistake. But you will be very happy you have a backup when the worst happens. Classical mistakes involves making a find with exec, but forgetting to target real files only (such as removing all 0 bytes files from a system => say goodbye to /dev, links, sockets etc.) and running a script with a badly set var (like export deluser="FOO"; rm -rf "/hom/$delusr"). Good luck on your learning. Jerome Herman