Linux Today: Linux News On Internet Time.
Search Linux Today
Linux News Sections:  Developer -  High Performance -  Infrastructure -  IT Management -  Security -  Storage -
Linux Today Navigation
LT Home
Contribute
Contribute
Link to Us
Linux Jobs


Top White Papers

More on LinuxToday


HowTo: Use Bash Parameter Substitution Like A Pro

Oct 14, 2010, 22:03 (0 Talkback[s])
(Other stories by Vivek Gite)

[ 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

Related Stories: