Originally Posted by mortonmorton
Thank you very much for that. So in this case, the use of $() is the appropriate way, and not the use of redirections? Is it not possible using redirections? I'm trying to understand when is redirection applicable over the $() expression. Or will it be just a case to case/ trial and error?
It depends on the command, whether it is written to receive information in its command line (its argument list) or on stdin.
In this case, cat requires the name of the file(s) in its arguments (ignoring the special case where the file name is not specified and it defaults to reading data from stdin) so, if you are generating the file name with locate, the $( ) is the only solution.
Other commands take the names of the file(s) to operate on from stdin. They are usually designed that way because the argument list might otherwise be greater than the system limit (4096 bytes?). The cpio command is an example/ It expects to receive file paths, one per line, on its stdin; in that case you would use a pipe, generating the path names with find or locate (for example).
Redirections simply read or write to files, most commonly being used to take stdin from a file or to write stdout and/or stderr to a file. You might have a list of files (in a file) that you want cpio to operate on. You could do it with a pipe
cat my_file_list | cpio ...
but more neatly with redirection
cpio ... < cat my_file_list
Output redirection is often used for logging
some commands >> my.log