Skip to Content
Learning Linux Shell Scripting - Second Edition
book

Learning Linux Shell Scripting - Second Edition

by Ganesh Sanjiv Naik
May 2018
Beginner
332 pages
7h 28m
English
Packt Publishing
Content preview from Learning Linux Shell Scripting - Second Edition

Understanding reading and writing to a file

In the earlier examples, we opened the file either for reading or writing. Now we will see how to open the file for reading and writing purposes:

    exec fd<> fileName
  

If the file descriptor number is not specified, then 0 will be used in its place. The file will be created if it does not exist. This procedure is useful for updating files.

Let's understand the following script.

Write the shell script file_03.sh as follows:

#!/bin/bash file_name="sample_out.txt" # We are assing fd number 3 to file. # We will be doing read and write operations on file exec 3<> $file_name # Writing to file echo """ Do not dwell in the past, do not dream of the future, concentrate the mind on the present moment. - Buddha ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Linux Shell Scripting

Learning Linux Shell Scripting

Ganesh Sanjiv Naik
Linux Shell Scripting Cookbook - Third Edition

Linux Shell Scripting Cookbook - Third Edition

Clif Flynt, Sarath Lakshman, Shantanu Tushar

Publisher Resources

ISBN: 9781788993197Supplemental Content