Shell Scripting: Expert Recipes for Linux, Bash and more

Shell Scripting: Expert Recipes for Linux, Bash and more

Steve Parker

Language: English

Pages: 600

ISBN: 1118024486

Format: PDF / Kindle (mobi) / ePub


A compendium of shell scripting recipes that can immediately be used, adjusted, and applied

The shell is the primary way of communicating with the Unix and Linux systems, providing a direct way to program by automating simple-to-intermediate tasks. With this book, Linux expert Steve Parker shares a collection of shell scripting recipes that can be used as is or easily modified for a variety of environments or situations. The book covers shell programming, with a focus on Linux and the Bash shell; it provides credible, real-world relevance, as well as providing the flexible tools to get started immediately.

  • Shares a collection of helpful shell scripting recipes that can immediately be used for various of real-world challenges
  • Features recipes for system tools, shell features, and systems administration
  • Provides a host of plug and play recipes for to immediately apply and easily modify so the wheel doesn't have to be reinvented with each challenge faced

Come out of your shell and dive into this collection of tried and tested shell scripting recipes that you can start using right away!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Shell Scripting Expert Recipes for Linux, Bash, and More Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxix ⊲⊲ Part I About the Ingredients Chapter 1 The History of Unix, GNU, and Linux. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Chapter 2 Getting Started. . . . . . . . . . . . . .

Torvalds was frustrated by its lack of features and the fact that it did not make full use of the (still relatively new) Intel 80386 processor, and in particular its “protected mode,” which allows for much better separation between the kernel and userspace. Relatively quickly, he got a working shell, and then got GCC, the GNU C compiler (now known as the GNU Compiler Collection, as it has been extended to compile various flavors of C, Fortran, Java, and Ada) working. At that stage, the kernel

“/bin/false” ] && [ ! -z “${home%\/var\/*}” ]; then echo “User $login ($name) lives in $home and uses `basename $shell`” fi done < /etc/passwd # Not necessary as we’re exiting the script, but it is good practice; # subsequent commands will want the normal IFS values. oIFS=$IFS $ ./ifs1.sh User root (root) lives in /root and uses bash User daemon (daemon) lives in /usr/sbin and uses sh User bin (bin) lives in /bin and uses sh User sys (sys) lives in /dev and uses sh User sync (sync) lives in /bin

start or end of a filename. This command lists all files containing the letter h. Notice that abc.php is included in this; as mentioned previously, the fact that a filename contains a period has no special significance. $ ls *h* abcdefghijk $ abc.php alphabet Although this is not filename expansion, another useful bash shell feature is the capability to expand a list of strings contained within curly brackets. This listing of /etc/rc*.d is more precisely matched by specifying the numbers

structure of a while loop is that you define the condition and then the code for it to execute while the condition remains true. This loop keeps doubling the value of a variable until it exceeds 100. $ cat while.sh #!/bin/bash i=1 while [ “$i” -lt “100” ] do echo “i is $i” i=`expr $i \* 2` done echo “Finished because i is now $i” $ ./while.sh i is 1 i is 2 i is 4 i is 8 i is 16 i is 32 i is 64 Finished because i is now 128 $ while.sh Because the condition is that i is less than 100, i gets to 64

Download sample

Download