Command Substitution - Shell Scripting

Command Substitution - Shell Scripting

Command Substitution - Shell Scripting - 5.0 out of 5 based on 1 vote
User Rating:  / 1
PoorBest 

Command substitution is used to execute a command and return the result to the shell script. This result will be stored in a variable

path=`printenv|grep PATH`

` is used to substitute a command. The command inside ` will be executed in a sub shell and the result will be returned back to the parent shell. This result is now stored in the corresponding variable.

path and PATH and two different variables.

| is called pipe. The output of one command is given as the input to another command.

printenv command will be executed first and the output will be given as the input for the grep command.

$(command) – is another way of command substitution

path=$(printenv |grep PATH)

 

 

 

You are here: Home Tutorials Shell Scripting Command Substitution