It is very useful to be able to store the output of a command to a shell variable for use in a script.

This can be achieved as follows:

shellVariableName=$(COMMAND)

Note that there is no space between the shellVariableName and the =, and the command is surround by $().

An example of outputting the most recently created file to a shell variable can be achieved as follows:

latestFilename=$(ls -t | head -n1 |awk '{printf("%s",$0)}')