Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

UNIX tips and tricks for a new user, Part 4: Some nifty shell tricks

Learn the basics of scripting with these powerful techniques

Michael Stutz, Author, Consultant
Photo of Michael Stutz
Michael Stutz is author of The Linux Cookbook, which he also designed and typeset using only open source software. His research interests include digital publishing and the future of the book. He has used various UNIX operating systems for 20 years.

Summary:  When writing a shell program, you often come across some special situation that you'd like to handle automatically. This tutorial includes examples of such situations from small Bourne shell scripts. These situations include base conversion from one string to another (decimal to hex, hex to decimal, decimal to octal, and so on), reading the keyboard while in a piped loop, subshell execution, inline input, executing a command once for each file in a directory, and multiple ways to construct a continuous loop. Part 4 of this series wraps up with a collection of shell one-liners that perform useful functions.

View more content in this series

Date:  20 Feb 2007
Level:  Intermediate PDF:  A4 and Letter (107 KB | 29 pages)Get Adobe® Reader®

Activity:  25680 views
Comments:  

Before you start

Learn what to expect from this tutorial and how to get the most out of it.

About this series

This series of tutorials provides a concise introduction to basic UNIX® concepts, written for the perspective of a new user. The three previous tutorials in the series provided a brush-up on UNIX systems geared toward new users coming from a Microsoft® Windows® background, describing the file system and common commands, an introduction to vi (the most ubiquitous of UNIX editors), and a quick primer on filters and regular expressions using the grep, sed, and awk tools.

About this tutorial

This tutorial provides a collection of shell tricks and tips that are handy for new users. It shows how to automate special situations using small scripts written in the Bourne shell, including automatic base conversion, reading keyboard input, executing commands in a subshell, executing commands on all the files in a directory, and various forms of looping. The tutorial concludes with a collection of useful shell one-liners.

Objectives

The objective of this tutorial is to show new users how to use and implement many of the shell's methods for providing automation at various levels. It demonstrates these methods by giving tricks and tips for special situations, and it also presents a rundown of useful shell one-liners for common tasks.

Prerequisites

This tutorial is written for users who are relatively new to UNIX. The only prerequisites are basic knowledge of the UNIX file system and the commands to manipulate it, the command line itself, and editing text files with an editor, such as vi. All of these concepts are fully described in the previous tutorials of this series.

System requirements

You need user-level access to a UNIX system with a Bourne-compatible shell environment, such as the popular bash shell. This is the only system requirement for this tutorial.

1 of 11 | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=AIX and UNIX, Linux
ArticleID=196816
TutorialTitle=UNIX tips and tricks for a new user, Part 4: Some nifty shell tricks
publish-date=02202007
author1-email=stutz@dsl.org
author1-email-cc=mmccrary@us.ibm.com

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.