Shell Scripting Recipes: A Problem-Solution Approach
Language: English
Pages: 351
ISBN: 148420221X
Format: PDF / Kindle (mobi) / ePub
"$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