Saturday, July 21, 2012

Copy and paste text with vi or vim

The ability to duplicate text in an editor can be handy. vi and vim have several useful copy and paste commands.


The command ‘Y’ or ‘yy’ copies (yanks) one or more lines. To copy one line, two lines, 10 lines, and all lines to the end of the file, respectively:
Y
2Y
10Y
yG

To paste the text contained in the buffer above (uppercase P) or below the current cursor position (lowercase p), respectively:
P
p

It is also possible to yank text within a line. The following commands yank text from the current cursor position to the end of the word and the end of the line, respectively:
yw
y$

The same commands paste the text within a line. Lower case p pastes after the cursor position and upper case P pastes before.
Paste will also work with deleted text, either lines or parts of lines. Be careful not to execute any other commands prior to pasting as this will empty the buffer.

Sunday, July 15, 2012

The Java EE 6 Tutorial


 

The Java EE 6 Tutorial

Eric Jendrock
Ian Evans
Devika Gollapudi
Kim Haase
William Markito Oliveira
Chinmayee Srivathsa

April 2012

XHTML Introduction

XHTML is HTML written as XML

What Is XHTML?

  • XHTML stands for EXtensible HyperText Markup Language
  • XHTML is almost identical to HTML 4.01
  • XHTML is a stricter and cleaner version of HTML
  • XHTML is HTML defined as an XML application
  • XHTML is a W3C Recommendation of January 2000.
  • XHTML is supported by all major browsers.

Why XHTML?

Many pages on the internet contain "bad" HTML.
The following HTML code will work fine if you view it in a browser (even if it does NOT follow the HTML rules):
<html>
<head>
<title>This is bad HTML</title>
<body>
<h1>Bad HTML
<p>This is a paragraph
</body>
XML is a markup language where documents must be marked up correctly and "well-formed".
If you want to study XML, Read our XML tutorial.
Today's market consists of different browser technologies. Some browsers run on computers, and some browsers run on mobile phones or other small devices. Smaller devices often lack the resources or power to interpret a "bad" markup language.
Therefore - by combining the strengths of HTML and XML, XHTML was developed. XHTML is HTML redesigned as XML.

The Most Important Differences from HTML:

DOCUMENT STRUCTURE
  • XHTML DOCTYPE is mandatory
  • The XML namespace attribute in <html> is mandatory
  • <html>, <head>, <title>, and <body> is mandatory
ELEMENT SYNTAX
  • XHTML elements must be properly nested
  • XHTML elements must always be closed
  • XHTML elements must be in lowercase
  • XHTML documents must have one root element
ATTRIBUTE SYNTAX
  • XHTML attribute names must be in lower case
  • XHTML attribute values must be quoted
  • XHTML attribute minimization is forbidden

<!DOCTYPE ....> Is Mandatory

An XHTML document must have a XHTML DOCTYPE declaration.
A complete list of XHTML Doctypes is found in W3Schools' Tags Reference.
The <html>, <head>, <title>, and <body> elements must also be present, and the xmlns attribute in <html>, must specify the xml namespace for the document.
The example below shows an XHTML document with a minimum of required tags:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Title of document</title>
</head>

<body>
......
</body>

</html>

How to Convert from HTML to XHTML

  1. Add an XHTML <!DOCTYPE> to the first line of every page
  2. Add an xmlns attribute to the html element of every page
  3. Change all element names to lowercase
  4. Close all empty elements
  5. Change all attribute names to lowercase
  6. Quote all attribute values

Validate XHTML With The W3C Validator

Put your web address in the box below:


XHTML Quiz Test

The test contains 20 questions and there is no time limit.
The test is not official, it's just a nice way to see how much you know, or don't know, about XHTML.
You will get 1 point for each correct answer. At the end of the Quiz, your total score will be displayed. Maximum score is 20 points.
Start the XHTML Quiz



Friday, July 13, 2012

Linux Documentation Project Guides


The Linux Documentation Project
home  |   HOWTOs  |   Guides  |   FAQs  |   man pages  |   Linux Gazette  |   LinuxFocus

 Linux Documentation Project Guides 


The Linux Documentation Project (LDP) is working on developing good, reliable documentation for the Linux operating system. The overall goal of the LDP is to collaborate in taking care of all of the issues of Linux documentation, ranging from online documentation (man pages, HTML, and so on) to printed manuals covering topics such as installing, using, and running Linux. Here is the Linux Documentation Project Manifesto and Copyright License for LDP works.
Translations of LDP works (languages other than English) can be found on the "Non-English Linux Info" links page.
A subset of Debian manuals are now available.
Additional documentation (HOWTOs, FAQs, etc) can be found here.
Older and unmaintained (but still pertinent) guides can be found here.
Search the LDP documents from our search page.

Current / Maintained Guides
  • Advanced Bash-Scripting Guide

    version: 6.5
    author: Mendel Cooper, <thegrendel.abs(at)gmail.com>
    last update: Apr 2012
    available formats:
    1. HTML (read online)
    2. HTML (read online, single file, 2.3M)
    3. HTML (tarred and gzipped package, 658K)
    4. PDF (2.6M)
    5. PostScript (1.4M)
    6. text (496K)
    7. PluckerDB (679K)
    This document is both a tutorial and a reference on shell scripting with Bash. It assumes no previous knowledge of scripting or programming, but progresses rapidly toward an intermediate/advanced level of instruction. The exercises and heavily-commented examples invite active reader participation. Still, it is a work in progress. The intention is to add much supplementary material in future updates to this document, as it evolves into a comprehensive book that matches or surpasses any of the shell scripting manuals in print.
  • Linux on the Road
    Linux with Laptops, Notebooks, PDAs, Mobile Phones and Other Portable Devices


    version: 3.22
    author: Werner Heuser, <wehe(at)tuxmobil.org>
    last update: Dec 2011
    available formats:
    1. HTML (read online)
    2. HTML (read online, single file, 580K)
    3. HTML (tarred and gzipped package, 820K)
    4. PDF (1.4M)
    5. PostScript (977K)
    6. text (448K)
    7. PluckerDB (248k)
    Though there are laptop, notebook, PDA and mobile phone related HOWTOs available already, this guide contains a concise survey of documents related to mobile computer devices. Also Linux features, such as installation methods for laptops, notebooks and PDAs as well as configurations for different (network) environments are described.
    Although there are some caveats, Linux is a better choice for mobile computer devices than most other operating systems. Because it supports numerous installation methods, works in many heterogenoues environments and needs smaller resources.
  • Windows+OpenSolaris+CentOS Installation Guide

    version: 1.2
    author: Subhasish Ghosh, <subhasish_ghosh(at)linuxwaves.com>
    last update: Jun 2009
    available formats:
    1. HTML (read online)
    2. HTML (tarred and gzipped package, 41k)
    3. PDF (535K)
    Explains how three different operating systems can be installed and configured on a single hard disk. The reader may choose from: Microsoft Windows NT/2K/XP + OpenSolaris 2008.11 + CentOS 5.2. Only x86 & x86-compatible architecture multi-booting is discussed and GNU GRUB is the boot loader of choice.
  • Bash Guide for Beginners

    version: 1.11
    author: Machtelt Garrels, <tille>
    last update: Dec 2008
    ISBN: 0-9744339-4-2
    available formats:
    1. HTML (read online)
    2. HTML (read online, single file, 530k)
    3. HTML (tarred and gzipped package, 514K)
    4. PDF (1.2M)
    5. PostScript (1.0M)
    6. text (110k)
    7. PluckerDB (165k)
    The Bash Guide for Beginners gets you started with Bash scripting and bridges the gap between the Bash HOWTO and the Advanced Bash Scripting Guide. Everybody who wants to make life easier on themselves, power users and sysadmins alike, can benefit from reading this practical course. The guide contains lots of examples and exercises at the end of each chapter, demonstrating the theory and helping you practice. Bash is available on a wide variety of UNIX, Linux, MS Windows and other systems.
  • Introduction to Linux - A Hands on Guide

    version: 1.27
    author: Machtelt Garrels, <tille>
    last update: Jun 2008
    ISBN: 1596821124
    available formats:
    1. HTML (read online)
    2. HTML (read online, single file, 800k)
    3. HTML (tarred and gzipped package, 1.1M)
    4. PDF (1.6M)
    5. PostScript (1.4M)
    6. text (187k)
    7. PluckerDB (254k)
    This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter. For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. We hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
  • GNU/Linux Command-Line Tools Summary

    version: 1.2
    author: Gareth Anderson, <somecsstudent(at)gmail.com>
    last update: Apr 2006
    available formats:
    1. HTML (read online)
    2. HTML (read online, single file, 559k)
    3. HTML (tarred and gzipped package, 317k)
    4. PDF (682k)
    5. PostScript (584k)
    6. text (gzipped, 88k)
    7. PluckerDB (238k)
    This document is an attempt to provide a summary of useful command-line tools available to a GNU/Linux based operating system, the tools listed are designed to benefit the majority of users and have being chosen at the authors discretion. This document is not a comprehensive list of every existent tool available to a GNU/Linux based system, nor does it have in-depth explanations of how things work. It is a summary which can be used to learn about and how to use many of the tools available to a GNU/Linux-based operating system.
  • LDP Author Guide

    version: 4.8
    authors: Mark F. Komarinski, <mkomarinski(at)wayga.org>
    Jorge Godoy, <godoy(at)metalab.unc.edu>
    David C. Merrill, <dcmerrill(at)mindspring.com>
    Emma Jane Hogbin
    last update: Apr 2006
    available formats:
    1. HTML (read online)
    2. HTML (read online, single file, 337k)
    3. HTML (tarred and gzipped package, 640k)
    4. PDF (1.4M)
    5. PostScript (1.5M)
    6. text (248k)
    7. PluckerDB (114k)
    This guide describes the process of submitting and publishing a document with The Linux Documentation Project (TLDP). It includes information about the tools, toolchains and formats used by TLDP. The document's primary audience is new TLDP authors, but it also contains information for seasoned documentation authors.
  • The Linux Kernel Module Programming Guide

    available versions: 2.4 and 2.6
    authors: Peter Jay Salzman, Michael Burian, Ori Pomerantz
    last update: May 2007 (kernel version 2.6)
    Jul 2004 (kernel version 2.4)
    available formats
    (kernel version 2.6):
    1. HTML (read online)
    2. HTML (read online, single file, 214k)
    3. HTML (tarred and gzipped package, 122k)
    4. PDF (539k)
    5. PluckerDB (155k)
    6. PostScript (497k)
    7. text (gzipped, 62k)
    available formats
    (kernel version 2.4):
    1. HTML (read online)
    2. HTML (read online, single file, 208k)
    3. HTML (tarred and gzipped package, 114k)
    4. PDF (153k)
    5. PostScript (65k)
    6. text (gzipped, 57k)
    A guide to programming Linux kernel modules.
  • The Linux System Administrators' Guide

    version: 0.9
    authors: Lars Wirzenius, Joanna Oja, Stephen Stafford, and Alex Weeks
    last update: July 2005
    available formats:
    1. HTML (read online)
    2. HTML (read online, single file, 436K)
    3. HTML (tarred and gzipped package, 178K)
    4. PDF (849K)
    5. PostScript (657K)
    6. text (375K)
    7. PluckerDB (170K)
    8. various (non-English) translations
    This is the third book in the main LDP series, and assumes knowledge of everything in the Installation and Users' Guides. It will cover all of the aspects of keeping the system running, handling user accounts, backups, configuration of the system, installing and upgrading software, and more. Whereas some of this information is in the Installation Guide (just to get the system off the ground) this book should be much more complete.

    Also visit the Linux System Administrators Guide Homepage.
  • Pocket Linux Guide

    version: 3.1
    author: David Horton, <dhorton(at)member.fsf.org>
    last update: Apr 2005
    available formats:
    1. HTML (read online)
    2. HTML (read online, single file, 194k)
    3. HTML (tarred and gzipped package, 59k)
    4. PDF (576k)
    5. PostScript (487k)
    6. text (171k)
    7. PluckerDB (75k)
    The Pocket Linux Guide is for anyone interested in learning the techniques of building a GNU/Linux system from source code. The guide is structured as a project that builds a small diskette-based GNU/Linux system called Pocket Linux. Each chapter explores a small piece of the overall system explaining how it works, why it is needed and how to build it. After completing the Pocket Linux project, readers should possess an enhanced knowledge of what makes GNU/Linux systems work as well as the confidence to explore larger, more complex source-code-only projects.
  • Guide to Managing Media and Public Relations in the Linux Community

    version: 1.1
    author: The Linux Professional Institute
    Sheldon Rose
    last update: Apr 2005
    available formats:
    1. HTML (read online)
    2. HTML (read online, single file, 129k)
    3. HTML (tarred and gzipped package, 52k)
    4. PDF (398k)
    5. PostScript (367k)
    6. text (113k)
    7. PluckerDB (62k)
    This guide provides useful information on how to generate positive public relations and news media coverage for Linux.
  • EVMS User Guide

    version: 2.4.0
    authors: Christine Lorenz, IBM
    Joy Goodreau, IBM
    Kylie Smith, IBM
    last update: September, 2004
    available formats:
    1. HTML (read online)
    2. HTML (read online, single file, 370k)
    3. HTML (tarred and gzipped package, 205k)
    4. PDF (423k)
    5. PostScript (210k)
    6. text (290k)
    7. PluckerDB (142k)
    This book is designed to address user's questions about Enterprise Volume Management System (EVMS) and provide a context for using EVMS. For additional information about EVMS or to ask questions specific to your distribution, the EVMS mailing lists are an excellent resource. You can view the list archives or subscribe to the lists from the EVMS Project web site.
  • Linux Dictionary

    version: 0.18
    author: Binh Nguyen, <linuxfilesystem(at)yahoo(dot)com(dot)au>
    last update: April 2005
    available formats:
    1. HTML (read online)
    2. HTML (read online, single file, 7.9M)
    3. HTML (tarred and gzipped package, 1.5M)
    4. PDF (8.0M)
    5. PostScript (1.7M)
    6. text (gzipped, 1.6M)
    7. PluckerDB (1.8M)
    8. directory listing (contains .deb and .rpm packages)
  • Linux Filesystem Hierarchy

    version: 0.65
    author: Binh Nguyen, <linuxfilesystem(at)yahoo.com.au>
    last update: July 2004
    available formats:
    1. HTML (read online)
    2. HTML (read online, single file, 354k)
    3. HTML (tarred and gzipped package, 119k)
    4. PDF (601k)
    5. PostScript (556k)
    6. text (399k)
    7. PluckerDB (133k)
    This document outlines the set of requirements and guidelines for file and directory placement under the Linux operating system according to those of the FSSTND v2.3 final (January 29, 2004) and also its actual implementation on an arbitrary system. It is meant to be accessible to all members of the Linux community, be distribution independent and is intended discuss the impact of the FSSTND and how it has managed to increase the efficiency of support interoperability of applications, system administration tools, development tools, and scripts as well as greater uniformity of documentation for these systems.
  • Custom Linux: A Porting Guide - Porting LinuxPPC to a Custom SBC

    version: 2.1
    author: Shie Erlich, <erlich(at)users.sourceforge.net>
    last update: Mar 2004
    available formats:
    1. HTML (read online)
    2. HTML (read online, single file, 60k)
    3. HTML (tarred and gzipped package, 25k)
    4. PDF (60k)
    5. PostScript (26k)
    6. text (56k)
    7. PluckerDB (32k)
    This guide describes a work in progress, to port Linux to a custom PowerPC-based board. This means making the operating system work on unfamiliar hardware. Anyone, who is on the same track might benefit from reading this paper, as it highlights the pitfalls and problematic points along the way.
  • Linux From Scratch

    version: 6.1.1
    author: Gerard Beekmans, <gerard(at)linuxfromscratch.org>
    last update: Nov 2005
    available formats:
    1. HTML (read online) (HTML.tar.bz2)
    2. HTML (read online, single file) (HTML.bz2)
    3. HTML (tarred and bzipped package)
    4. PDF (PDF.bz2)
    5. text (txt.bz2)
    6. text (XML.tar.bz2)
    Derived from the popular Linux-From-Scratch-HOWTO, this book describes the process of creating your own Linux system from scratch from an already installed Linux distribution, using nothing but the sources of software that are needed.
    More information can be found at http://www.linuxfromscratch.org.
  • The Bugzilla Guide

    version: 2.16.3
    author: Matthew P. Barnson, <mbarnson@sisna.com>
    last update: April 2003
    available formats:
    1. HTML (read online)
    2. HTML (tarred and gzipped package, 261k)
    3. PDF (465k)
    This document is intended to be the comprehensive guide to the installation, administration, maintenance, and use of the Bugzilla bug-tracking system.
  • Linux Kernel 2.4 Internals

    author: Tigran Aivazian, <tigran@veritas.com>
    last update: August 2002
    available formats:
    1. HTML (read online)
    2. HTML (tarred and gzipped package, 80k)
    3. PDF (256k)
    An introduction to the Linux 2.4 kernel. The author is working as senior Linux kernel engineer at VERITAS Software Ltd and wrote this book for the purpose of supporting the short training course/lectures he gave on this subject, internally at VERITAS.
  • Securing & Optimizing Linux: The Ultimate Solution

    version: 2.0
    author: Gerhard Mourani, <gmourani@openna.com>
    last update: July 2002
    available formats:
    1. PDF (6.2MB)
    2. Example server configuration files (tar file; described in book as "floppy.tgz").
    Mastering security with Linux and getting the maximum out of your system have never been easier. Securing & Optimizing Linux: The Ultimate Solution (v2.0) has been written and achieved with tightening security to an incomparable level in mind. One of its main features is the easy path from beginning to end in a smooth manner, step by step for beginners as well as for experts.
    More information (and updates) available from: http://www.openna.com/products/books.php.
    older version: Securing and Optimizing Linux Red Hat Edition - A Hands on Guide
    version: 1.3
    author: Gerhard Mourani, <gmourani@openna.com>
    last update: August 2000
    available formats:
    1. HTML (read online)
    2. HTML (tarred and gzipped package, 1.5MB)
    3. PDF (4.9MB)
    4. Example server configuration files (tar file; described in book as "floppy.tgz").
  • Emacspeak User's Guide

    version: 1.3
    author: Jennifer Jobst, <jobst@us.ibm.com>
    last update: July 2002
    available formats:
    1. HTML (read online)
    2. HTML (tarred and gzipped package, 23k)
    3. PDF (89k)
    This document helps Emacspeak users become familiar with Emacs as an audio desktop and provides tutorials on many common tasks and the Emacs applications available to perform those tasks.
  • The Linux Cookbook: Tips and Techniques for Everyday Use
    Removed at the author's request.
  • The Linux Network Administrator's Guide, Second Edition

    version: 1.1
    authors: Olaf Kirch and Terry Dawson
    last update: March 2000
    ISBN: 1-56592-400-2
    available formats:
    1. HTML (read online)
    2. HTML (tarred and gzipped package, 690k)
    3. PDF (1.5MB)
    This book was written to provide a single reference for network administration in a Linux environment. Beginners and experienced users alike should find the information they need to cover nearly all important administration activities required to manage a Linux network configuration. The possible range of topics to cover is nearly limitless, so of course it has been impossible to include everything there is to say on all subjects. We've tried to cover the most important and common ones. We've found that beginners to Linux networking, even those with no prior exposure to Unix-like operating systems, have found this book good enough to help them successfully get their Linux network configurations up and running and get them ready to learn more.
  • Linux Administrator's Security Guide
    Removed at the request of the author (book is now more "dynamic"). Please access the Linux Administrator's Security Guide at the following location: http://www.seifried.org/lasg/
  • Linux System Administration Made Easy

    version: 1.06
    author: Steve Frampton
    last update: November 1999
    available formats:
    1. HTML (read online)
    2. HTML (tarred and gzipped package, 99k)
    3. other : PDF, PostScript, text, and SGML source
    The Linux Administration Made Easy (LAME) guide attempts to describe day-to-day administration and maintenance issues commonly faced by Linux system administrators.
    This book can be purchased from bookstores, more information can be found here.

Older / Unmaintained (but still pertinent) Guides

  • The Linux Network Administrators' Guide

    version: 1.0
    author: Olaf Kirch
    last update: March 1996
    available formats:
    1. HTML (read online)
    2. HTML (tarred and gzipped package, 332k)
    3. other : plain text, DVI, LaTeX source, PDF, and PostScript.
    4. various (non-English) translations
    This guide supplements the System Administrators' Guide and cover all of the diverse issues of networking under Linux, from UUCP to serial connections to TCP/IP. Many Linux users won't have access to such a network, so this information is in a separate manual. It contains an intro to TCP/IP and UUCP (for those who have never used such networks before, lots of background information), TCP/IP, UUCP, SLIP, and DNS configuration, configuration of mail systems such as sendmail and Smail, setting up NNTP and news, and NFS.
  • The Linux Programmer's Guide

    version: 0.4
    authors: B. Scott Burkett, Sven Goldt, John D. Harper, Sven van der Meer and Matt Welsh
    last update: March 1996
    available formats:
    1. PDF (recommended format)
    2. HTML (read online)
    3. HTML (tarred and gzipped package, 140k)
    4. other : DVI, LaTeX source, PDF and PostScript.
    5. Example source code is also available.
    6. various (non-English) translations
    The Linux Programmer's Guide is meant to do what the name implies -- It is to help Linux programmers understand the peculiarities of Linux. By its nature, this also means that it should be useful when porting programs from other operating systems to Linux. Therefore, this guide must describe the system calls and the major kernel changes which have effects on older programs like serial I/O and networking.
  • The Linux Users' Guide

    version: beta-1
    author: Larry Greenfield
    last update: December 1996
    available formats:
    1. other : DVI, PDF (gzipped / zipped), PostScript (gzipped / zipped), and LaTeX source
    2. various (non-English) translations
    This book covers all of the user-end aspects of Linux, from sitting down at the first login session to using complex tools such as gcc, emacs, and so on. It assumes no previous Unix experience, so not only will it serve as an introduction to Linux, but to Unix in general as well. This manual won't cover system administrator tasks (i.e. anything that needs to be done as root) - it's for the J. Random User who has a working Linux system sitting in front of them.
  • The Linux Kernel Hackers' Guide

    version: not available
    author: Michael K. Johnson
    last update: August 1998
    available formats:
    1. HTML (read online)
    2. HTML (tarred and gzipped package, 468k)
    This is an older, archived instance; complete with discussion threads (no posting or replying however).
  • Installation and Getting Started Guide

    version: 3.2
    authors: Matt Welsh and others
    last update: March 1998
    available formats:
    1. HTML (read online)
    2. HTML (tarred and gzipped package, 836k)
    This book is for personal computer users who want to install and use Linux. The book assumes that you have basic knowledge about personal computers and operating systems like MS-DOS, but no previous knowledge of Linux or UNIX.
  • The Linux Kernel

    version: 0.8-3
    author: David A. Rusling
    last update: January 1998
    available formats:
    1. HTML (read online)
    2. HTML (tarred and gzipped package, 376k)
    The kernel is at the heart of the operating system. This book is a guide to how the kernel fits together, how it works; a tour of the kernel.

Translated Guides
Below is a table of translated guides that are available from pub/Linux/docs/ldp-archived/.    Additional translations of LDP works and translated documentation not listed here may be found on the "Non-English Linux Info" page.

de en es fr it ja pl pt ru sl
Kernel Hackers Guide   en                
Network Guide   en es              
Programmers Guide   en es              
System Administration Guide   en es fr it     pt    
Users Guide   en es   it          


 legend:
de = German, en = English, es = Spanish, fr = French, it = Italian, ja = Japanese,
pl = Polish, pt = Portuguese, ru = Russian, sl = Slovenian


Debian Manuals and Guides
(updated nightly)
"An important part of any operating system is documentation, the technical manuals that describe the operation and use of programs. As part of its efforts to create a high-quality free operating system, the Debian Project is making every effort to provide all of its users with proper documentation in an easily accessible form."   -- from Debian Documentation home page

Additional Guides of Interest
  • Linux Palm Developer's Quick Start Guide

    version: 1.0
    author(s): Jim Weller
    last update: February 2001
    available formats:
    1. HTML (read online)
    2. PDF (72K)
    This guide is intended to help those new to palm programming get started. It assumes a fair knowledge of linux and gnu tools. It takes you from clueless to able to compile a HelloWorld type application.
  • TrinityOS: A Guide to Configuring Your Linux Server for Performance, Security, and Managability

    author(s): David A. Ranch
    available formats:
    1. Various formats available from another website
    TrinityOS and its associated archive scripts guide the Linux user in a step-by-step fashion using a common example throughout to configure over 50+ Internet services. The main focus of TrinityOS is to do this in a secure fashion while keeping both performance and managability in mind. The documents also guide the user in other advanced topics such as aquiring their own Internet domain(s), moving DNS servers, confirming if you've been hacked, fighting SPAM email, and fixing various Linux file system, partition, LILO, and data recovery problems.
  • VideoLAN Quickstart

    author(s): the VideoLAN project
    last update: September 2003
    available formats:
    1. HTML (read online)
    2. tarred/gzipped (106K)
    3. PDF (440K)
    4. text
    5. (8.5M)
    This document describes how to start using VideoLAN quickly.
  • VLC (VideoLAN Client) User Guide

    author(s): the VideoLAN project
    last update: September 2003
    available formats:
    1. HTML (read online)
    2. tarred/gzipped (118K)
    3. PDF (506K)
    4. text
    This document is the complete user guide of VLC, the VideoLAN Client.
  • VLS (VideoLAN Server) User Guide

    author(s): the VideoLAN project
    last update: September 2003
    available formats:
    1. HTML (read online)
    2. tarred/gzipped (123K)
    3. PDF (471K)
    4. text
    This document is the complete user guide of VLS, the VideoLAN Server.
home  |   HOWTOs  |   Guides  |   FAQs  |   man pages  |   Linux Gazette  |   LinuxFocus
Last Modified: 2012-07-07 |  feedback@en.tldp.org

Thursday, July 12, 2012

Advanced Bash-Scripting Guide

Advanced Bash-Scripting Guide

An in-depth exploration of the art of shell scripting

Mendel Cooper

6.5
05 Apr 2012
Revision History
Revision 6.327 Apr 2011Revised by: mc
'SWOZZLEBERRY' release
Revision 6.430 Aug 2011Revised by: mc
'VORTEXBERRY' release
Revision 6.505 Apr 2012Revised by: mc
'TUNGSTENBERRY' release
This tutorial assumes no previous knowledge of scripting or programming, but progresses rapidly toward an intermediate/advanced level of instruction . . . all the while sneaking in little nuggets of UNIX® wisdom and lore. It serves as a textbook, a manual for self-study, and a reference and source of knowledge on shell scripting techniques. The exercises and heavily-commented examples invite active reader participation, under the premise that the only way to really learn scripting is to write scripts.
This book is suitable for classroom use as a general introduction to programming concepts.

Dedication

For Anita, the source of all the magic
Table of Contents
Part 1. Introduction
1. Shell Programming!
2. Starting Off With a Sha-Bang
Part 2. Basics
3. Special Characters
4. Introduction to Variables and Parameters
5. Quoting
6. Exit and Exit Status
7. Tests
8. Operations and Related Topics
Part 3. Beyond the Basics
9. Another Look at Variables
10. Manipulating Variables
11. Loops and Branches
12. Command Substitution
13. Arithmetic Expansion
14. Recess Time
Part 4. Commands
15. Internal Commands and Builtins
16. External Filters, Programs and Commands
17. System and Administrative Commands
Part 5. Advanced Topics
18. Regular Expressions
19. Here Documents
20. I/O Redirection
21. Subshells
22. Restricted Shells
23. Process Substitution
24. Functions
25. Aliases
26. List Constructs
27. Arrays
28. Indirect References
29. /dev and /proc
30. Network Programming
31. Of Zeros and Nulls
32. Debugging
33. Options
34. Gotchas
35. Scripting With Style
36. Miscellany
37. Bash, versions 2, 3, and 4
38. Endnotes
38.1. Author's Note
38.2. About the Author
38.3. Where to Go For Help
38.4. Tools Used to Produce This Book
38.5. Credits
38.6. Disclaimer
Bibliography
A. Contributed Scripts
B. Reference Cards
C. A Sed and Awk Micro-Primer
C.1. Sed
C.2. Awk
D. Exit Codes With Special Meanings
E. A Detailed Introduction to I/O and I/O Redirection
F. Command-Line Options
F.1. Standard Command-Line Options
F.2. Bash Command-Line Options
G. Important Files
H. Important System Directories
I. An Introduction to Programmable Completion
J. Localization
K. History Commands
L. Sample .bashrc and .bash_profile Files
M. Converting DOS Batch Files to Shell Scripts
N. Exercises
N.1. Analyzing Scripts
N.2. Writing Scripts
O. Revision History
P. Download and Mirror Sites
Q. To Do List
R. Copyright
S. ASCII Table
Index
List of Examples
2-1. cleanup: A script to clean up log files in /var/log
2-2. cleanup: An improved clean-up script
2-3. cleanup: An enhanced and generalized version of above scripts.
3-1. Code blocks and I/O redirection
3-2. Saving the output of a code block to a file
3-3. Running a loop in the background
3-4. Backup of all files changed in last day
4-1. Variable assignment and substitution
4-2. Plain Variable Assignment
4-3. Variable Assignment, plain and fancy
4-4. Integer or string?
4-5. Positional Parameters
4-6. wh, whois domain name lookup
4-7. Using shift
5-1. Echoing Weird Variables
5-2. Escaped Characters
5-3. Detecting key-presses
6-1. exit / exit status
6-2. Negating a condition using !
7-1. What is truth?
7-2. Equivalence of test, /usr/bin/test, [ ], and /usr/bin/[
7-3. Arithmetic Tests using (( ))
7-4. Testing for broken links
7-5. Arithmetic and string comparisons
7-6. Testing whether a string is null
7-7. zmore
8-1. Greatest common divisor
8-2. Using Arithmetic Operations
8-3. Compound Condition Tests Using && and ||
8-4. Representation of numerical constants
8-5. C-style manipulation of variables
9-1. $IFS and whitespace
9-2. Timed Input
9-3. Once more, timed input
9-4. Timed read
9-5. Am I root?
9-6. arglist: Listing arguments with $* and $@
9-7. Inconsistent $* and $@ behavior
9-8. $* and $@ when $IFS is empty
9-9. Underscore variable
9-10. Using declare to type variables
9-11. Generating random numbers
9-12. Picking a random card from a deck
9-13. Brownian Motion Simulation
9-14. Random between values
9-15. Rolling a single die with RANDOM
9-16. Reseeding RANDOM
9-17. Pseudorandom numbers, using awk
10-1. Inserting a blank line between paragraphs in a text file
10-2. Generating an 8-character "random" string
10-3. Converting graphic file formats, with filename change
10-4. Converting streaming audio files to ogg
10-5. Emulating getopt
10-6. Alternate ways of extracting and locating substrings
10-7. Using parameter substitution and error messages
10-8. Parameter substitution and "usage" messages
10-9. Length of a variable
10-10. Pattern matching in parameter substitution
10-11. Renaming file extensions:
10-12. Using pattern matching to parse arbitrary strings
10-13. Matching patterns at prefix or suffix of string
11-1. Simple for loops
11-2. for loop with two parameters in each [list] element
11-3. Fileinfo: operating on a file list contained in a variable
11-4. Operating on files with a for loop
11-5. Missing in [list] in a for loop
11-6. Generating the [list] in a for loop with command substitution
11-7. A grep replacement for binary files
11-8. Listing all users on the system
11-9. Checking all the binaries in a directory for authorship
11-10. Listing the symbolic links in a directory
11-11. Symbolic links in a directory, saved to a file
11-12. A C-style for loop
11-13. Using efax in batch mode
11-14. Simple while loop
11-15. Another while loop
11-16. while loop with multiple conditions
11-17. C-style syntax in a while loop
11-18. until loop
11-19. Nested Loop
11-20. Effects of break and continue in a loop
11-21. Breaking out of multiple loop levels
11-22. Continuing at a higher loop level
11-23. Using continue N in an actual task
11-24. Using case
11-25. Creating menus using case
11-26. Using command substitution to generate the case variable
11-27. Simple string matching
11-28. Checking for alphabetic input
11-29. Creating menus using select
11-30. Creating menus using select in a function
12-1. Stupid script tricks
12-2. Generating a variable from a loop
12-3. Finding anagrams
15-1. A script that spawns multiple instances of itself
15-2. printf in action
15-3. Variable assignment, using read
15-4. What happens when read has no variable
15-5. Multi-line input to read
15-6. Detecting the arrow keys
15-7. Using read with file redirection
15-8. Problems reading from a pipe
15-9. Changing the current working directory
15-10. Letting let do arithmetic.
15-11. Showing the effect of eval
15-12. Using eval to select among variables
15-13. Echoing the command-line parameters
15-14. Forcing a log-off
15-15. A version of rot13
15-16. Using set with positional parameters
15-17. Reversing the positional parameters
15-18. Reassigning the positional parameters
15-19. "Unsetting" a variable
15-20. Using export to pass a variable to an embedded awk script
15-21. Using getopts to read the options/arguments passed to a script
15-22. "Including" a data file
15-23. A (useless) script that sources itself
15-24. Effects of exec
15-25. A script that exec's itself
15-26. Waiting for a process to finish before proceeding
15-27. A script that kills itself
16-1. Using ls to create a table of contents for burning a CDR disk
16-2. Hello or Good-bye
16-3. Badname, eliminate file names in current directory containing bad characters and whitespace.
16-4. Deleting a file by its inode number
16-5. Logfile: Using xargs to monitor system log
16-6. Copying files in current directory to another
16-7. Killing processes by name
16-8. Word frequency analysis using xargs
16-9. Using expr
16-10. Using date
16-11. Date calculations
16-12. Word Frequency Analysis
16-13. Which files are scripts?
16-14. Generating 10-digit random numbers
16-15. Using tail to monitor the system log
16-16. Printing out the From lines in stored e-mail messages
16-17. Emulating grep in a script
16-18. Crossword puzzle solver
16-19. Looking up definitions in Webster's 1913 Dictionary
16-20. Checking words in a list for validity
16-21. toupper: Transforms a file to all uppercase.
16-22. lowercase: Changes all filenames in working directory to lowercase.
16-23. du: DOS to UNIX text file conversion.
16-24. rot13: ultra-weak encryption.
16-25. Generating "Crypto-Quote" Puzzles
16-26. Formatted file listing.
16-27. Using column to format a directory listing
16-28. nl: A self-numbering script.
16-29. manview: Viewing formatted manpages
16-30. Using cpio to move a directory tree
16-31. Unpacking an rpm archive
16-32. Stripping comments from C program files
16-33. Exploring /usr/X11R6/bin
16-34. An "improved" strings command
16-35. Using cmp to compare two files within a script.
16-36. basename and dirname
16-37. A script that copies itself in sections
16-38. Checking file integrity
16-39. Uudecoding encoded files
16-40. Finding out where to report a spammer
16-41. Analyzing a spam domain
16-42. Getting a stock quote
16-43. Updating FC4
16-44. Using ssh
16-45. A script that mails itself
16-46. Generating prime numbers
16-47. Monthly Payment on a Mortgage
16-48. Base Conversion
16-49. Invoking bc using a here document
16-50. Calculating PI
16-51. Converting a decimal number to hexadecimal
16-52. Factoring
16-53. Calculating the hypotenuse of a triangle
16-54. Using seq to generate loop arguments
16-55. Letter Count"
16-56. Using getopt to parse command-line options
16-57. A script that copies itself
16-58. Exercising dd
16-59. Capturing Keystrokes
16-60. Securely deleting a file
16-61. Filename generator
16-62. Converting meters to miles
16-63. Using m4
17-1. Setting a new password
17-2. Setting an erase character
17-3. secret password: Turning off terminal echoing
17-4. Keypress detection
17-5. Checking a remote server for identd
17-6. pidof helps kill a process
17-7. Checking a CD image
17-8. Creating a filesystem in a file
17-9. Adding a new hard drive
17-10. Using umask to hide an output file from prying eyes
17-11. Backlight: changes the brightness of the (laptop) screen backlight
17-12. killall, from /etc/rc.d/init.d
19-1. broadcast: Sends message to everyone logged in
19-2. dummyfile: Creates a 2-line dummy file
19-3. Multi-line message using cat
19-4. Multi-line message, with tabs suppressed
19-5. Here document with replaceable parameters
19-6. Upload a file pair to Sunsite incoming directory
19-7. Parameter substitution turned off
19-8. A script that generates another script
19-9. Here documents and functions
19-10. "Anonymous" Here Document
19-11. Commenting out a block of code
19-12. A self-documenting script
19-13. Prepending a line to a file
19-14. Parsing a mailbox
20-1. Redirecting stdin using exec
20-2. Redirecting stdout using exec
20-3. Redirecting both stdin and stdout in the same script with exec
20-4. Avoiding a subshell
20-5. Redirected while loop
20-6. Alternate form of redirected while loop
20-7. Redirected until loop
20-8. Redirected for loop
20-9. Redirected for loop (both stdin and stdout redirected)
20-10. Redirected if/then test
20-11. Data file names.data for above examples
20-12. Logging events
21-1. Variable scope in a subshell
21-2. List User Profiles
21-3. Running parallel processes in subshells
22-1. Running a script in restricted mode
23-1. Code block redirection without forking
23-2. Redirecting the output of process substitution into a loop.
24-1. Simple functions
24-2. Function Taking Parameters
24-3. Functions and command-line args passed to the script
24-4. Passing an indirect reference to a function
24-5. Dereferencing a parameter passed to a function
24-6. Again, dereferencing a parameter passed to a function
24-7. Maximum of two numbers
24-8. Converting numbers to Roman numerals
24-9. Testing large return values in a function
24-10. Comparing two large integers
24-11. Real name from username
24-12. Local variable visibility
24-13. Demonstration of a simple recursive function
24-14. Another simple demonstration
24-15. Recursion, using a local variable
24-16. The Fibonacci Sequence
24-17. The Towers of Hanoi
25-1. Aliases within a script
25-2. unalias: Setting and unsetting an alias
26-1. Using an and list to test for command-line arguments
26-2. Another command-line arg test using an and list
26-3. Using or lists in combination with an and list
27-1. Simple array usage
27-2. Formatting a poem
27-3. Various array operations
27-4. String operations on arrays
27-5. Loading the contents of a script into an array
27-6. Some special properties of arrays
27-7. Of empty arrays and empty elements
27-8. Initializing arrays
27-9. Copying and concatenating arrays
27-10. More on concatenating arrays
27-11. The Bubble Sort
27-12. Embedded arrays and indirect references
27-13. The Sieve of Eratosthenes
27-14. The Sieve of Eratosthenes, Optimized
27-15. Emulating a push-down stack
27-16. Complex array application: Exploring a weird mathematical series
27-17. Simulating a two-dimensional array, then tilting it
28-1. Indirect Variable References
28-2. Passing an indirect reference to awk
29-1. Using /dev/tcp for troubleshooting
29-2. Playing music
29-3. Finding the process associated with a PID
29-4. On-line connect status
30-1. Print the server environment
30-2. IP addresses
31-1. Hiding the cookie jar
31-2. Setting up a swapfile using /dev/zero
31-3. Creating a ramdisk
32-1. A buggy script
32-2. Missing keyword
32-3. test24: another buggy script
32-4. Testing a condition with an assert
32-5. Trapping at exit
32-6. Cleaning up after Control-C
32-7. A Simple Implementation of a Progress Bar
32-8. Tracing a variable
32-9. Running multiple processes (on an SMP box)
34-1. Numerical and string comparison are not equivalent
34-2. Subshell Pitfalls
34-3. Piping the output of echo to a read
36-1. shell wrapper
36-2. A slightly more complex shell wrapper
36-3. A generic shell wrapper that writes to a logfile
36-4. A shell wrapper around an awk script
36-5. A shell wrapper around another awk script
36-6. Perl embedded in a Bash script
36-7. Bash and Perl scripts combined
36-8. A (useless) script that recursively calls itself
36-9. A (useful) script that recursively calls itself
36-10. Another (useful) script that recursively calls itself
36-11. A "colorized" address database
36-12. Drawing a box
36-13. Echoing colored text
36-14. A "horserace" game
36-15. A Progress Bar
36-16. Return value trickery
36-17. Even more return value trickery
36-18. Passing and returning arrays
36-19. Fun with anagrams
36-20. Widgets invoked from a shell script
36-21. Test Suite
37-1. String expansion
37-2. Indirect variable references - the new way
37-3. Simple database application, using indirect variable referencing
37-4. Using arrays and other miscellaneous trickery to deal four random hands from a deck of cards
37-5. A simple address database
37-6. A somewhat more elaborate address database
37-7. Testing characters
37-8. Reading N characters
37-9. Using a here document to set a variable
37-10. Piping input to a read
37-11. Negative array indices
37-12. Negative parameter in string-extraction construct
A-1. mailformat: Formatting an e-mail message
A-2. rn: A simple-minded file renaming utility
A-3. blank-rename: Renames filenames containing blanks
A-4. encryptedpw: Uploading to an ftp site, using a locally encrypted password
A-5. copy-cd: Copying a data CD
A-6. Collatz series
A-7. days-between: Days between two dates
A-8. Making a dictionary
A-9. Soundex conversion
A-10. Game of Life
A-11. Data file for Game of Life
A-12. behead: Removing mail and news message headers
A-13. password: Generating random 8-character passwords
A-14. fifo: Making daily backups, using named pipes
A-15. Generating prime numbers using the modulo operator
A-16. tree: Displaying a directory tree
A-17. tree2: Alternate directory tree script
A-18. string functions: C-style string functions
A-19. Directory information
A-20. Library of hash functions
A-21. Colorizing text using hash functions
A-22. More on hash functions
A-23. Mounting USB keychain storage devices
A-24. Converting to HTML
A-25. Preserving weblogs
A-26. Protecting literal strings
A-27. Unprotecting literal strings
A-28. Spammer Identification
A-29. Spammer Hunt
A-30. Making wget easier to use
A-31. A podcasting script
A-32. Nightly backup to a firewire HD
A-33. An expanded cd command
A-34. A soundcard setup script
A-35. Locating split paragraphs in a text file
A-36. Insertion sort
A-37. Standard Deviation
A-38. A pad file generator for shareware authors
A-39. A man page editor
A-40. Petals Around the Rose
A-41. Quacky: a Perquackey-type word game
A-42. Nim
A-43. A command-line stopwatch
A-44. An all-purpose shell scripting homework assignment solution
A-45. The Knight's Tour
A-46. Magic Squares
A-47. Fifteen Puzzle
A-48. The Towers of Hanoi, graphic version
A-49. The Towers of Hanoi, alternate graphic version
A-50. An alternate version of the getopt-simple.sh script
A-51. The version of the UseGetOpt.sh example used in the Tab Expansion appendix
A-52. Cycling through all the possible color backgrounds
A-53. Morse Code Practice
A-54. Base64 encoding/decoding
A-55. The Gronsfeld Cipher
A-56. Basics Reviewed
C-1. Counting Letter Occurrences
I-1. Completion script for UseGetOpt.sh
L-1. Sample .bashrc file
L-2. .bash_profile file
M-1. VIEWDATA.BAT: DOS Batch File
M-2. viewdata.sh: Shell Script Conversion of VIEWDATA.BAT
S-1. A script that generates an ASCII table