May 2018
Beginner
332 pages
7h 28m
English
The following is the syntax for storing the output of a command in a file:
Command >& fd
./script >& fd
The following is the illustrative example script, file_08.sh:
#!/bin/bash exec 4> output.txt cat /proc/cpuinfo >&4 exec 3<&-
Save the file, give the permission to execute, and run the script as follows:
$ chmod u+x file_08.sh
$ ./file_08.sh
Here's the output:

In this example, we have executed the command cat /proc/cpuinfo and we have stored the output in the file, output.txt.