#!/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.sh
and.txt
files are just text files. – Kusalananda Feb 18 '19 at 19:26numbers.txt
properly line-terminated? What happens if you changewhile read p
towhile read p || [ -n "$p" ]
? – steeldriver Feb 18 '19 at 19:30read
can only read complete lines. – Kusalananda Feb 18 '19 at 19:33read
reads the line (and assigns it to variablep
) but returns false, having encountered EOF while doing so: hence the body of thewhile
loop is not executed. – steeldriver Feb 18 '19 at 19:40