Command Substitution in a Bash Shell Script
Feb 08, 2011, 03:04 (0 Talkback[s])
[ Thanks to Andrew
Weber for this link. ]
"Command substitution is when you take the output of
one command and use it as the argument for another command. If you
simply invoke the date utility, you'll get the following output.
date
Fri Jan 19 17:13:29 EST 2007
"That works here, but it might not work well in other cases,
like when you're writing a bash script. You would then need to
consider using command substitution. There are two ways to do
this.
"The first way is the more modern way, and is really the only
way that you want to use. You surround the command that you want to
substitute with parentheses, and then precede it with a
dollar-sign. Here, we're using echo to show the output of
date."
Complete Story
Related Stories:
- Bash as CGI language(Feb 06, 2011)
- The reason why I have switched to zsh - Part 1(Feb 03, 2011)
- Collect User Input in a Bash Shell Script(Feb 02, 2011)
- Scripting the Linux desktop, Part 1: Basics(Feb 01, 2011)
- Positional Parameters in the Bash Shell(Jan 31, 2011)
- Expect Script Tutorial: Expressions, If Conditions, For Loop, and While Loop Examples(Jan 20, 2011)
- Using Pipes in the Bash Shell(Jan 10, 2011)