O'Reilly logo

Korn Shell: Unix and Linux Programming Manual, Third Edition, The by Anatole Olczak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Command Substitution

Command substitution is a feature that allows output to be expanded from a command. It can be used to assign the output of a command to a variable, or to imbed the output of a command within another command. The format for command substitution is:

					$(command)
				

where command is executed and the output is substituted for the entire $(command) construct. For example, to print the current date in a friendly format:

					$ echo The date is $(date)
					The date is Fri Jul 27 10:41:21 PST 1996
				

or see who is logged on:

					$ echo $(who —q) are logged on now
					root anatole are logged on now
				

Any commands can be used inside $(...), including pipes, I/O operators, metacharacters (wildcards), and more. We can find out how many users are logged ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required