Shell Scripting Recipes: A Problem-Solution Approach

Shell Scripting Recipes: A Problem-Solution Approach

Language: English

Pages: 351

ISBN: 148420221X

Format: PDF / Kindle (mobi) / ePub


Filled with over 150 essential, practical recipes that empower Unix users to regain lost time
spent creating and testing shell scripts. The majority of scripts included are POSIX-compliant
and supported by many of the major shell variants, including Bash, ksh, and sh.
Each real-world example recipe follows the same problem-solution structure, meaning
cross-referencing is easy and fast. Recipe topics include file conversion (DOS, UNIX, and
Mac), system administration, resource monitoring, filename management, complex date
calculations, screen control capabilities, and much more.
Completely updated for this second edition and taking all the changes of the past ten
years into account, every recipe in this book is now relevant for a modern audience. Authors
Chris Johnson’s and Jayant Varma’s code is clear, direct, and applicable. Add this excellent
reference to your library today.

 

 

 

 

 

 

 

 

 

 

 

"$file" > "$tempfile" && mv "$tempfile" "$file" done 2.2 unix2dos—Convert a Unix File to Windows Under Windows, a file with Unix line endings (just LF), may look even stranger than a Windows file on Unix: #! /bin/sh echo "Defenestration required" exit   ■■Tip  While some methods of copying from one system to another will do the conversion, it could be safer to convert a file explicitly before copying. How It Works This script adds a carriage return to the end of each line so that all lines

-gt $r_num ] do _REPEAT=${_REPEAT%?} done }   repeat() { _repeat "$@" && printf "%s\n" "${_REPEAT}" } Notes I have tried concatenating more instances of $_REPEAT at one time, and found that, using bash on my system, three is the optimum number in each iteration of the while loop. This may vary from shell to shell and system to system, as it depends on the string handling functions used by the shell. Try it with more, if you like; your system may behave differently. 3.9 index, rindex—Find

the first letter after a space or hyphen has been removed is capitalized. Apostrophes are removed, but they do not affect the letter count. The words are printed in three tab-separated fields: the squished words, the original phrase, and the word lengths. Here are a few examples: AladdinsLamp blueGreenAlgae swordOfDamocles wireHairedTerrier Aladdin's lamp (8,4) blue-green algae sword of Damocles wire-haired terrier (4-5,5) (5,2,8) (4-6,7)  89 Chapter 4 ■ What’s in a Word? Usage wf-compounds

Replace a Pattern in a String�������������������������������������������������������������������������������� 73 3.8 repeat—Build a String of a Specified Length��������������������������������������������������������������������������������� 75 3.9 index, rindex—Find Position of One String Within Another������������������������������������������������������������ 76 3.10 substr—Extract a Portion of a

Briefs��������������������������������������������������������������������������������������� 63 ■Chapter ■ 4: What’s in a Word?������������������������������������������������������������������������������ 83 ■Chapter ■ 5: Scripting by Numbers���������������������������������������������������������������������� 107 ■Chapter ■ 6: Loose Names Sink Scripts: Bringing Sanity to Filenames��������������� 139 ■Chapter ■ 7: Treading a Righteous

Download sample

Download