File Handling in Shell Scripts [Bash]

Posted By: Matpal - April 03, 2018

Create a file

Following shell script can create the file to a directory. In this example, it creates a text file in current directory.
#!/bin/bash

echo "This is a text." > sample.txt

Reading a file

!/bin/bash
value=$(<sample.txt)
echo "$value"

Reading a file per line

#!/bin/bash

while read line; do

echo $line
 done < sample.txt

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.