Linux

  1. Home
  2. Computing & Technology
  3. Linux

GNU/Linux Command-Line Tools Summary

From Authors, for About.com


   GNU/Linux Command-Line Tools Summary
   Prev    Chapter 6. Directing Input/Output    Next

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”.


           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.



   Prev    Home    Next
   Usage    Up    Performing more than one command


* License

* GNU/Linux Command-Line Tools Summary Index

Explore Linux

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Linux

  1. Home
  2. Computing & Technology
  3. Linux
  4. Linux Documentation
  5. Linux Tools Summary
  6. GNU/Linux Command-Line Tools Summary - Command Substitution

©2009 About.com, a part of The New York Times Company.

All rights reserved.