Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions

  




 

 

6.3. Command Substitution

Command substitution is basically another way to do a pipe, you can use pipes and command substitution interchangeably, it's up to you which one you find easier...

Command substitution can be done in two distinct ways.

 

Method One (back-quotes)

 

Simply type:

command_1 `command_2 -options`

This will execute "command_2" and it's output will become the input to "command_1".

Tip Backquote key
 

The back-quote key is usually located at the same place as the tilde, above the [Tab] key.

Method Two (dollars sign)

 

Simply type:

command_1 $(command_2)

This will execute "command_2" and it's output will become the input to "command_1".

Using the pipe instead

 

You can of course use pipes to do the same thing, if you don't know what a pipe is, please see Section 6.2. For example instead of doing:

less $cat file1.txt file2.txt

You could do:

cat file1.txt file2.txt | less

And end up with exactly the same result, it's up to you which way you find easier.

 
 
  Published under the terms of the GNU General Public License Design by Interspire