HowTo: Use Bash Parameter Substitution Like A Pro | Linux Today

HowTo: Use Bash Parameter Substitution Like A Pro

Written By
Web Webster
Web Webster
Oct 15, 2010

[ Thanks to An Anonymous Reader for
this link. ]

“The $ character is used for parameter expansion, and
command substitution. You can use it for manipulating and/or
expanding variables on demands without using external commands such
as sed or awk.

#1: Getting Up Default Shell Variables Value

“The syntax is as follows:

${parameter:-defaultValue}
var=${parameter:-defaultValue}

“If parameter not set, use defaultValue. In this example, your
shell script takes arguments supplied on the command line. You’d
like to provide default value so that the most common value can be
used without needing to type them every time. If variable $1 is not
set or passed, use root as default value for u:

u=${1:-root}

“Consider the following example:”


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.