文档介绍:Linux Shell Scripting Cookbook
Copyright © 2011 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system,
or transmitted in any form or by any means, without the prior written permission of the
publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without
warranty, either express or implied. Neither the author, nor Packt Publishing, and its
dealers and distributors will be held liable for any damages caused or alleged to be
caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
First published: January 2011
Production Reference: 1200111
Published by Packt Publishing Ltd.
32 Lincoln Road
Olton
Birmingham, B27 6PA, UK.
ISBN 978-1-849513-76-0
Cover Image by Charwak A (charwak86@)
Table of Contents
Preface 1
Chapter 1: Shell Something Out 7
Introduction 7
Printing in the terminal 9
Playing with variables and environment variables 12
Doing math calculations with the shell 17
Playing with file descriptors and redirection 19
Arrays and associative arrays 25
Visiting aliases 27
Grabbing information about terminal 29
Getting, setting dates, and delays 30
Debugging the script 33
Functions and arguments 35
Reading the output of a sequence mands 38
Reading "n" characters without pressing Return 40
Field separators and iterators 41
Comparisons and tests 44
Chapter 2: Have a mand 49
Introduction 50
Concatenating with cat 50
Recording and playback of terminal sessions 53
Finding files and file listing 55
Playing with xargs 63