The following is a summary of the exec command for using various file handling-related operations:
Command |
What it does |
exec command |
This command will replace shell and execute it. Therefore, it will not return to its original shell, which started it. |
exec > data.txt |
This opens data.txt for writing standard output. |
exec < data.txt |
This opens data.txt for reading standard input. |
exec 3< data.txt |
This opens data.txt for reading with descriptor 3. |
sort <&3 |
This will sort the data.txt file. |
exec 4> data.txt |
This opens data.txt for writing with descriptor 4. |
ll >&4 |
The output of ll is redirected to data.txt. |
exec 6<&5 |
This makes fd 6 a copy of fd 5. |