• Complain

Jayant Varma - Shell Scripting Recipes: A Problem-Solution Approach

Here you can read online Jayant Varma - Shell Scripting Recipes: A Problem-Solution Approach full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2015, publisher: Apress, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Jayant Varma Shell Scripting Recipes: A Problem-Solution Approach
  • Book:
    Shell Scripting Recipes: A Problem-Solution Approach
  • Author:
  • Publisher:
    Apress
  • Genre:
  • Year:
    2015
  • Rating:
    4 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 80
    • 1
    • 2
    • 3
    • 4
    • 5

Shell Scripting Recipes: A Problem-Solution Approach: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Shell Scripting Recipes: A Problem-Solution Approach" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Shell Scripting Recipes is filled with over 150 much-needed and practical recipes that follow a problem-solution format, and help all Unix users regain some of the lost time spent creating and testing shell scripts. Most scripts in this book are POSIX (Portable Operating System Interface)-compliant, so they are supported by many of the major shell variants, including Bash, ksh, and sh, among others. This completely updated second edition takes into account the many changes to shell scripting that have occurred since its original publication nearly ten years ago, and all the recipes are now relevant for a modern audience.

Each real-world example recipe follows the same structure and easily shows you whats going on in each case. File conversion (DOS, UNIX, and Mac), system administration, and resource monitoring are just a few of the topics covered in this highly practical shell scripting reference. You will also find recipes for filename management, complex date calculations, screen control capabilities, and more.

Author Chris Johnsons code is clear, direct, and applicable, and he explains everything well in each recipe so that you understand not just how to do something, but why to do it that way. Shell Scripting Recipes is an invaluable book and one to add to your library today.

What youll learn
  • How to effectively use the POSIX shell and command-line utilities
  • How to use strings, numbers, words, and filenames with ease
  • Effective file management and file conversion (DOS, UNIX, and Mac)
  • How to monitor resources effectively
  • How to perform complex date calculations
  • Manage a POP3 email server
Who this book is for

This book is for anyone who has the basic knowledge of what shell scripting is and wants to learn how to use it properly. Each recipes is explained clearly and the book begins with the simplest recipes, so all you need is a basic knowledge of what shell scripting is.

Table of Contents1: The POSIX Shell and Command-Line Utilities

2: Playing with Files: Viewing, Manipulating, and Editing Text Files

3: String Briefs

4: Whats in a Word?

5: Scripting by Numbers

6: Loose Names Sink Scripts: Bringing Sanity to Filenames

7: Treading a Righteous PATH

8: The Dating Game

9: Good Housekeeping: Monitoring and Tidying Up File Systems

10: Screenplay: The screen-funcs Library

11: Aging, Archiving, and Deleting Files

12: Covering All Your Databases

13: Home on the Web

14:Taking Care of Business

15: Random Acts of Scripting

16: A Smorgasbord of Scripts

17: Script Development Management

Appendix: Internet Scripting Resources

Jayant Varma: author's other books


Who wrote Shell Scripting Recipes: A Problem-Solution Approach? Find out the surname, the name of the author of the book and a list of all author's works by series.

Shell Scripting Recipes: A Problem-Solution Approach — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Shell Scripting Recipes: A Problem-Solution Approach" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Chris F. A. Johnson and Jayant Varma 2015
Chris F. A. Johnson and Jayant Varma Shell Scripting Recipes 10.1007/978-1-4842-0220-3_1
Chapter 1: The POSIX Shell and Command-Line Utilities
Chris F. A. Johnson 1 and Jayant Varma 1
(1)
Ontario, Canada
The POSIX shell is a descendant of the KornShell, which is a descendant of the Bourne shell. The basic syntax has remained the same, and Bourne shell scripts will usually run successfully in a POSIX shell. Not all of the KornShell features are included in POSIX (there are no arrays, for example), but the most important ones are. Those, which would be important to many developers, are string manipulation and arithmetic.
The scripts in this book make extensive use of features of the POSIX shell, and keep external commands to a minimum. This chapter presents an overview of the features of the POSIX shell and the external Unix commands used in this book, without going into great detail. Further information is available in the documentation for the shell and the various commands as well as on many web pages, a number of which are listed in the Appendix. We will also explain some of the idiosyncrasies used in the scripts, and present a library of functions that are used by many scripts.
Shell Commands
These descriptions are brief overviews of the built-in commands; for a complete description, see your shells man page.
echo
The echo command prints its arguments separated by single spaces followed by a newline. If an unquoted variable contains characters present in $IFS (see Parameters and Variables later in this chapter), then the variable will be split on those characters:
$ list="a b c d e f g h"
$ echo $list
a b c d e f g h
If the variable is quoted, all internal characters will be preserved:
$ echo "$list"
a b c d e f g h
In the early days of Unix, two different versions of echo appeared. One version converted escape sequences, such as \t and \n , into the characters they represent in the C language; \c suppressed the newline, and discarded any further characters. The other used the -n option to suppress the trailing newline and did not convert escape sequences. The POSIX standard for echo says that Implementations shall not support any options and If the first operand is -n , or if any of the operands contain a backslash (\) character, the results are implementation-defined. In other words, you cannot rely on echo s behavior being one or the other. It is best not to use echo unless you know exactly what echo is going to print, and you know that it will not contain any problem characters. The preferred command is printf .
printf
This command may be built into the shell itself, or it may be an external command. Like the C-language function on which it is based, printf takes a format operand that describes how the remaining arguments are to be printed, and any number of optional arguments. The format string may contain literal characters, escape sequences, and conversion specifiers. Escape sequences (the most common ones being \n for newline, \t for tab, and \r for carriage return) in format will be converted to their respective characters. Conversion specifiers, %s , %b , %d , %x , and %o , are replaced by the corresponding argument on the command line. Some implementations support other specifiers, but they are not used in this book. When there are more arguments than spec-ifiers, the format string is reused until all the arguments have been consumed.
The %s specifier interprets its argument as a string and prints it literally:
$ printf "%s\n" "qwer\ty" 1234+5678
qwer\ty
1234+5678
The %b specifier is like %s , but converts escape sequences in the argument:
$ printf "%b\n" "qwer\ty" "asdf\nghj"
qwer y
asdf
ghj
The %d , %x , and %o specifiers print their arguments as decimal, hexadecimal, and octal numbers, respectively.
$ printf "%d %x %o\n" 15 15 15
15 f 17
The conversion specifiers may be preceded by flags for width specification, optionally preceded by a minus sign indicating that the conversion is to be printed flush left, instead of flush right, in the specified number of columns:
$ printf "%7d:\n%7s:\n%-7s:\n" 23 Cord Auburn
23:
Cord:
Auburn :
In a numeric field, a before the width flag indicates padding with zeroes:
$ printf "%07d\n" 13
0000013
set
In the Oxford English Dictionary , the longest entry is for the word set thirty-two pages in my Compact Edition. In the Unix shell, the set command is really three commands in one. Without any arguments, it prints the names and values of all shell variables (including functions). With one or more option arguments, it alters the shells behavior. Any non-option arguments are placed in the positional parameters.
Only three options to set are used in this book:
  • -v : Print shell input lines as they are read.
  • -x : Print commands and their arguments as they are executed.
  • -f : Disable file name generation (globbing).
Given this script, which is call xx.sh ,
echo "Number of positional parameters: $#"
echo "First parameter: ${1:-EMPTY}"
shift $(( $# - 1 ))
echo "Last parameter: ${1:-EMPTY}"
its output is this:
$ xx.sh the quick brown fox
Number of positional parameters: 4
First parameter: the
Last parameter: fox
If set -v is added to the top of the script, and the standard output redirected to oblivion, the script itself is printed:
$ xx.sh the quick brown fox >/dev/null
echo "Number of positional parameters: $#"
echo "First parameter: ${1:-EMPTY}"
shift $(( $# - 1 ))
echo "Last parameter: ${1:-EMPTY}"
If set -v is replaced with set -x , variables and arithmetic expressions are replaced by their values when the lines are printed; this is a useful debugging tool:
$ xx.sh the quick brown fox >/dev/null
++ echo 'Number of positional parameters: 4'
++ echo 'First parameter: the'
++ shift 3
++ echo 'Last parameter: fox'
++ exit
To demonstrate the set -f option, and the use of + to reverse the operation, run the following script in an empty directory:
## Create a number of files using brace expansion (bash, ksh)
touch {a,b,c,d}${RANDOM}_{e,r,g,h}${RANDOM}
## Turn off filename expansion
set -f
printf "%-22s%-22s%-22s\n" * ; echo ## Display asterisk
printf "%-22s%-22s%-22s\n" *h* ; echo ## Display "*h*"
## Turn filename expansion back on
set +f
printf "%-22s%-22s%-22s\n" * ; echo ## Print all filenames
printf "%-22s%-22s%-22s\n" *h* ; echo ## Print filenames containing "h"
When the script is run, this is the output:
$ xx.sh
*
*h*
a12603_e6243 a28923_h23375 a29140_r28413
a5760_g7221 b17774_r4121 b18259_g11343
b18881_e10656 b660_h32228 c22841_r19358
c26906_h14133 c29993_g6498 c6576_e25837
d11453_h12972 d25162_e3276 d7984_r25591
d8972_g31551
a28923_h23375 b660_h32228 c26906_h14133
d11453_h12972
You can use set to split strings into pieces by changing the value of $IFS . For example, to split a date, which could be 2005-03-01 or 2003/09/29 or 2001.01.01, $IFS can be set to all the possible characters that could be used as separators. The shell will perform word splitting on any character contained in $IFS :
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Shell Scripting Recipes: A Problem-Solution Approach»

Look at similar books to Shell Scripting Recipes: A Problem-Solution Approach. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Shell Scripting Recipes: A Problem-Solution Approach»

Discussion, reviews of the book Shell Scripting Recipes: A Problem-Solution Approach and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.