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]

LPI exam 102 prep, Topic 109: Shells, scripting, programming, and compiling

Junior Level Administration (LPIC-1) topic 109

Ian Shields, Senior Programmer, IBM
Ian Shields
Ian Shields works on a multitude of Linux projects for the developerWorks Linux zone. He is a Senior Programmer at IBM at the Research Triangle Park, NC. He joined IBM in Canberra, Australia, as a Systems Engineer in 1973, and has since worked on communications systems and pervasive computing in Montreal, Canada, and RTP, NC. He has several patents and has published several papers. His undergraduate degree is in pure mathematics and philosophy from the Australian National University. He has an M.S. and Ph.D. in computer science from North Carolina State University. Learn more in Ian's profile on My developerWorks.
(An IBM developerWorks Contributing Author)

Summary:  In this tutorial, Ian Shields continues preparing you to take the Linux Professional Institute® Junior Level Administration (LPIC-1) Exam 102. In this fifth in a series of nine tutorials, Ian introduces you to the Bash shell, and scripts and programming in the Bash shell. By the end of this tutorial, you will know how to customize your shell environment, use shell programming structures to create functions and scripts, set and unset environment variables, and use the various login scripts.

View more content in this series

Date:  30 Jan 2007
Level:  Intermediate PDF:  A4 and Letter (179 KB | 45 pages)Get Adobe® Reader®

Activity:  22984 views
Comments:  

Before you start

Learn what these tutorials can teach you and how you can get the most from them.

About this series

The Linux Professional Institute (LPI) certifies Linux system administrators at two levels: junior level (also called "certification level 1") and intermediate level (also called "certification level 2"). To attain certification level 1, you must pass exams 101 and 102; to attain certification level 2, you must pass exams 201 and 202.

developerWorks offers tutorials to help you prepare for each of the four exams. Each exam covers several topics, and each topic has a corresponding self-study tutorial on developerWorks. For LPI exam 102, the nine topics and corresponding developerWorks tutorials are:

Table 1. LPI exam 102: Tutorials and topics
LPI exam 102 topicdeveloperWorks tutorialTutorial summary
Topic 105 LPI exam 102 prep:
Kernel
Learn how to install and maintain Linux kernels and kernel modules.
Topic 106 LPI exam 102 prep:
Boot, initialization, shutdown, and runlevels
Learn how to boot a system, set kernel parameters, and shut down or reboot a system.
Topic 107 LPI exam 102 prep:
Printing
Learn how to manage printers, print queues and user print jobs on a Linux system.
Topic 108 LPI exam 102 prep:
Documentation
Learn how to use and manage local documentation, find documentation on the Internet and use automated logon messages to notify users of system events.
Topic 109 LPI exam 102 prep:
Shells, scripting, programming, and compiling
(This tutorial.) Learn how to customize shell environments to meet user needs, write Bash functions for frequently used sequences of commands, write simple new scripts, using shell syntax for looping and testing, and customize existing scripts. See the detailed objectives below.
Topic 111 LPI exam 102 prep:
Administrative tasks
Coming soon.
Topic 112 LPI exam 102 prep:
Networking fundamentals
Coming soon.
Topic 113 LPI exam 102 prep:
Networking services
Coming soon.
Topic 114 LPI exam 102 prep:
Security
Coming soon.

To pass exams 101 and 102 (and attain certification level 1), you should be able to:

  • Work at the Linux command line
  • Perform easy maintenance tasks: help out users, add users to a larger system, back up and restore, and shut down and reboot
  • Install and configure a workstation (including X) and connect it to a LAN, or connect a stand-alone PC via modem to the Internet

To continue preparing for certification level 1, see the developerWorks tutorials for LPI exams 101 and 102, as well as the entire set of developerWorks LPI tutorials.

The Linux Professional Institute does not endorse any third-party exam preparation material or techniques in particular. For details, please contact info@lpi.org.


About this tutorial

Welcome to "Shells, scripting, programming, and compiling," the fifth of nine tutorials designed to prepare you for LPI exam 102. In this tutorial, you learn how to use the Bash shell, how to use shell programming structures to create functions and scripts, how to customize your shell environment, how to set and unset environment variables, and how to use the various login scripts.

The title for this tutorial duplicates the corresponding topic in the LPI 102 exam, and therefore includes "programming and compiling," but the LPI objectives limit "programming" to that required for writing shell functions and scripts. And no objectives for compiling programs are included in the topic.

This tutorial is organized according to the LPI objectives for this topic. Very roughly, expect more questions on the exam for objectives with higher weight.

Table 2. Shells, scripting, programming, and compiling: Exam objectives covered in this tutorial
LPI exam objectiveObjective weightObjective summary
1.109.1
Customize and use the shell environment
Weight 5Customize shell environments to meet user needs. Set environment variables (at login or when spawning a new shell). Write Bash functions for frequently used sequences of commands.
1.109.2
Customize or write simple scripts
Weight 3Write simple Bash scripts and customize existing ones.

Prerequisites

To get the most from this tutorial, you should have a basic knowledge of Linux and a working Linux system on which to practice the commands covered in this tutorial.

This tutorial builds on content covered in previous tutorials in this LPI series, so you may want to first review the tutorials for exam 101. In particular, you should be thoroughly familiar with the material from the "LPI exam 101 prep (topic 103): GNU and UNIX commands" tutorial, as many of the building blocks for this tutorial were covered in that tutorial, especially the section "Using the command line."

Different versions of a program may format output differently, so your results may not look exactly like the listings and figures in this tutorial.

1 of 5 | 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=Linux, Open source, AIX and UNIX
ArticleID=193176
TutorialTitle=LPI exam 102 prep, Topic 109: Shells, scripting, programming, and compiling
publish-date=01302007
author1-email=ishields@us.ibm.com
author1-email-cc=

Table of contents

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.