Linux Gazette: Introduction to Shell Scripting | Linux Today

Linux Gazette: Introduction to Shell Scripting

Written By
Web Webster
Web Webster
Sep 23, 2000

“At this point in the series, we’re getting pretty close to
what I consider the upper limit of basic shell scripting; there are
still a few areas I’d like to cover, but most of the issues
involved are getting rather, umm, involved. A good example is the
`tput’ command that I’ll be covering this month:
in order to
really understand what’s going on, as opposed to just using it,
you’d need to learn all about “termcap/terminfo” controversy
(A.K.A. one of the main arguments in the “Why UNIX Sucks” debate) –
a deep, involved, ugly issue (for a fairly decent and simple
explanation, see Hans de Goede’s fixkeys.tgz, which contains a neat
little “HOWTO”. For a more in-depth study, the
Keyboard-and-Console-HOWTO is an awesome reference on the subject).
I’ll try to make sense despite the confusion, but be warned…”

“The concept of functions is not a difficult one, but is
certainly very useful: they are simply blocks of code that you can
execute under a single label. Unlike a script, they do not spawn a
new subshell but execute within the current one. They can be used
within a script, or stand-alone. … Functions may also be loaded
into the environment, and invoked just like shell scripts; we’ll
talk about sourcing functions later on. For those of you who use
Midnight Commander, check out the “mc ()” function described in
their man page – it’s a very useful one, and is loaded from
“.bashrc”.”

“Important item: functions are created as “function
pour_the_beer () { … }” or “pour_the_beer () { … }” (the
keyword is optional); they are invoked as “pour_the_beer” (no
parentheses). Also, be very careful (as in, _do not_ unless you
really mean it) about using an “exit” statement in a function:
since you’re running the code in the current shell, this will cause
you to exit your current (i.e. the “login”) shell! Exiting a shell
script this way can produce some very ugly results, like a `hung’
shell that has to be killed from another VT (yep, I’ve
experimented). The statement that will terminate a function without
killing the shell is “return”.”

Complete
Story

Web Webster

Web Webster

Web Webster has more than 20 years of writing and editorial experience in the tech sector. He’s written and edited news, demand generation, user-focused, and thought leadership content for business software solutions, consumer tech, and Linux Today, he edits and writes for a portfolio of tech industry news and analysis websites including webopedia.com, and DatabaseJournal.com.

Linux Today Logo

LinuxToday is a trusted, contributor-driven news resource supporting all types of Linux users. Our thriving international community engages with us through social media and frequent content contributions aimed at solving problems ranging from personal computing to enterprise-level IT operations. LinuxToday serves as a home for a community that struggles to find comparable information elsewhere on the web.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.