How do I store information in a .dat file

1.6k views Asked by At

I have been struggling to read information and store it into a .dat file, but everytime I run my bash script it seems to run ok but the .dat file I have made is empty.

Here is my code:

#!/bin/bash
echo "Please enter student's name:"
read student
echo "$student"
((count = 0))

while read students[$count] ; do
((count++))
done < sorted.dat

Am I missing something obvious?

2

There are 2 answers

0
Oo.oO On BEST ANSWER

Maybe you have to store student in the file?

#!/bin/bash
echo "Please enter student's name:"
read student
echo "$student" >> sorted.dat
((count = 0))

while read students[$count] ; do
((count++))
done < sorted.dat
0
karan patel On

.dat file is like a simple text file you can read and write in a normal way

echo "Today's date is" date >> stored.dat
date >> stored.dat
cat stored.dat