Loading...
Shell Script

Command Substitution

The Bourne shell can redirect a command’s standard output back to the shell’s own command line i.e., the command’s output can be used as an argument to another command, or it can store the command output in a shell variable. It can be done by enclosing a command in the back quote (`) or in braces(()).

Syntax:
Var=`command`

OR
Var=$(command)

$ PROC=`ps -ef  |grep user1
$ echo $PROC
root 8428 8388 0 14:20 pts/1 00:00:00 su - user1
user1 8429 8428 0  14:20 pts/1 00:00:00 -bash
user1 8457 8429 0  14:20 pts/1 00:00:00 -ksh
user1 8507 8457 0  14:30 pts/1 00:00:00 -ef
Leave a Reply

Your email address will not be published. Required fields are marked *