Program output as an argument

The output of any program can be placed in a command line (or as the right hand side of an assignment) by enclosing the invocation in back quotes: `cmd` or using the preferred syntax $(cmd). However back quotes are still widely used in scripts.

For example, we can use ls and use its output as an argument to our line counting script from the previous section.

[alice@onyx shell-examples]: lc.sh $(/bin/ls)
3 files
      5 hello.sh
      6 lc.sh
      3 numusers
     14 total
[alice@onyx shell-examples]:

Note that we specified /bin/ls instead of ls because the ls command was aliased to ls -color, which would not work because the color options adds special characters in the listing. By using the full pathname of the command, we are bypassing the alias. Alternately, we could have unalias'd ls before using it.