Skip to Content
Pro Bash Programming: Scripting the GNU/Linux Shell
book

Pro Bash Programming: Scripting the GNU/Linux Shell

by Chris F.A. Johnson
October 2009
Beginner to intermediate
242 pages
5h 4m
English
Apress
Content preview from Pro Bash Programming: Scripting the GNU/Linux Shell

CHAPTER 4Command-Line Parsing and Expansion

One of the strengths of the shell as a programming language is its parsing of command-line arguments and the various expansions it performs on words in the line. When a command is called with arguments, the shell does several things before it invokes the command.

To help visualize what happens, the short script shown in Listing 4-1, called sa, will display what the shell has passed to it after processing all the arguments. Each of its arguments is printed on a separate line, preceded by the value of $pre and followed by the value of $post.

Listing 4-1. sa; Displaying Command-Line Arguments

pre=: post=: printf "$pre%s$post\n" "$@"

The special parameter $@ expands to a list of all the command-line ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Pro Bash Programming : Scripting the GNU/Linux Shell, Second Edition

Pro Bash Programming : Scripting the GNU/Linux Shell, Second Edition

Chris F. A. Johnson, Jayant Varma
Linux Shell Scripting Cookbook - Third Edition

Linux Shell Scripting Cookbook - Third Edition

Clif Flynt, Sarath Lakshman, Shantanu Tushar

Publisher Resources

ISBN: 9781430219972Purchase book