Let's write a script to read from a file:
Write the script file_02.sh, shown as follows:
#!/bin/bash # We will open file sample_input.txt for reading purpose. # We are assigning descriptor 3 to the file. exec 3< sample_input.txt cat <&3 # Closing file exec 3<&-
Save the file, give the permission to execute, and run the script as follows:
$ chmod u+x file_02..sh
We will create the sample_input.txt file as follows:
$ echo "Hello to All" > sample_input.txt
Run the script and check the result:
$ ./file_02.sh
This should produce the following output:
Hello to All