4.4. Command substitution

Command substitution allows the output of a command to be substituded anywhere a variable can be used. The command may be a function call, shell builtin or external program.

Example 4.5. Using substitutions.

This example shows the use of command substitution with a builtin, a function and an external program.

>lsout="$(ls \(flash1\))"
>echo ${lsout}
MD5Sums MD5Sums.able bin bootimg.000 bootimg.009 doc
>fbout="$(fbset)"
>echo ${fbout}
mode 800x600-60 # D: 40.000 MHz, H: 37.878 KHz, V: 60.315 Hz, geometry 800 600
>function foo { echo -n $1; echo "baz"; [ "$2" = "bar" ] || echo "foo bar baz"; }
>funcout="$(foo bar baz)"
>echo ${funcout}
barbazfoo bar baz
>