Command Substitution Assignment Help

Assignment Help: >> Shell Programming - Command Substitution

Command Substitution

Command substitution permits   capturing the output of any command as an argument for   another command. Whenever a command line is placed inside (tilde or backquotes characters), the shell first runs the command or commands after that replaces the entire expression, involving the backquotes, with the output. This characteristic is frequently used to provide values to shell variables. Let's consider the following

# today='date'

In the given syntax this assigns the string representing the current date to the variable today.

# echo $today

This will display the output of date command.

The subsequent assignment saves, in the files variable and the number of files in the current directory:

# files='ls | wc -l'

The given command

# echo $files

It will show the total number of files in the current directory.

Command substitution can be performed on any command which writes to the standard output. To nest command substitutions, every of the nested backquotes have to be preceded through a \ (backslash), as in the given syntax

# logmsg='echo Your login directory is \'pwd\"# show the directory#

# echo $logmsg

Your login directory is /home/manu

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd