#!/bin/bash
while read p
do
echo "$p"
done < numbers.txt
This script is only reading and allowing me to print .sh files. I have tried it with .txt files (like above but it does not print anything.)
#!/bin/bash
while read p
do
echo "$p"
done < numbers.txt
This script is only reading and allowing me to print .sh files. I have tried it with .txt files (like above but it does not print anything.)
That's because you are printing test not variable p
Try this:
#!/bin/bash
while read p
do
echo "$p"
done < numbers.txt
Test:
$ cat numbers.txt
1
2
345
678
9
$ bash script.sh
1
2
345
678
9
$
numbers.txt. The filename suffix means nothing on Unix systems. Both.shand.txtfiles are just text files. – Kusalananda Feb 18 '19 at 19:26numbers.txtproperly line-terminated? What happens if you changewhile read ptowhile read p || [ -n "$p" ]? – steeldriver Feb 18 '19 at 19:30readcan only read complete lines. – Kusalananda Feb 18 '19 at 19:33readreads the line (and assigns it to variablep) but returns false, having encountered EOF while doing so: hence the body of thewhileloop is not executed. – steeldriver Feb 18 '19 at 19:40