LinuxProgramming: Hello Universe 2: Mastering the Command Line | Linux Today

LinuxProgramming: Hello Universe 2: Mastering the Command Line

Written By
Web Webster
Web Webster
Jun 20, 2000

[ Thanks to Kevin
Reichard
for this link. ]

“In the abstract, this “ignore command-line options” approach is
appealing–after all, what’s the point of festooning our programs
with all those widgets, except to give the user complete control
over the program? But once we move from fuzzy abstracts like “all
GUI applications” to specific programs with real needs, the scene
changes radically, and before you can say “user request” you’re
faced with a slew of minor issues, some of which can best be solved
with good old-fashioned command-line processing.”

“To no one’s surprise, there are several ways to tiptoe through
command-line options under Linux. You can manually process the
argc/argv variable passed to your main() function, if you like, but
that’s a pain, it’s another opportunity to add obscure bugs to your
program, and it can lead to code maintenance hassles when you
(inevitably) add new features to your program. A more
programmer-friendly approach is to use Linux’s getopt_long()
function, which is what I did in this installment of Hello Universe
to give the user some control over the font and colors the program
uses.”

“There are essentially two kinds of options you need to worry
about, and options can either take an argument (as opposed to
causing one) or not, for a total of four combinations. I can’t
begin to provide a comprehensive treatment of command line
processing here, so I’ll present just a basic technique that
requires an argument for each option, but lets you use either a
single dash and letter (“-h”) or a double dash and a complete word
(“–help”) for the options.”


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.