Shell script won't reading non- .sh files [duplicate]

Clash Royale CLAN TAG#URR8PPP
This question already has an answer here:
Read a line-oriented file which may not end with a newline
6 answers
#!/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.)
shell-script
 marked as duplicate by Kusalananda
 StackExchange.ready(function() 
 if (StackExchange.options.isMobile) return;
 $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() 
 var $hover = $(this).addClass('hover-bound'),
 $msg = $hover.siblings('.dupe-hammer-message');
 $hover.hover(
 function() 
 $hover.showInfoMessage('', 
 messageElement: $msg.clone().show(),
 transient: false,
 position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
 dismissable: false,
 relativeToBody: true
 );
 ,
 function() 
 StackExchange.helpers.removeMessages();
 
 );
 );
 );
 Feb 18 at 19:36
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
|
show 5 more comments
This question already has an answer here:
Read a line-oriented file which may not end with a newline
6 answers
#!/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.)
shell-script
 marked as duplicate by Kusalananda
 StackExchange.ready(function() 
 if (StackExchange.options.isMobile) return;
 $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() 
 var $hover = $(this).addClass('hover-bound'),
 $msg = $hover.siblings('.dupe-hammer-message');
 $hover.hover(
 function() 
 $hover.showInfoMessage('', 
 messageElement: $msg.clone().show(),
 transient: false,
 position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
 dismissable: false,
 relativeToBody: true
 );
 ,
 function() 
 StackExchange.helpers.removeMessages();
 
 );
 );
 );
 Feb 18 at 19:36
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Please add a sample of the contents ofnumbers.txt. The filename suffix means nothing on Unix systems. Both.shand.txtfiles are just text files.
– Kusalananda
Feb 18 at 19:26
I added a screen shot of both files
– Cesa Salaam
Feb 18 at 19:29
2
Please, don't post images of text.
– Kusalananda
Feb 18 at 19:32
1
Your file does not contain a single terminated line.readcan only read complete lines.
– Kusalananda
Feb 18 at 19:33
1
I guess it would be more correct to say thatreadreads 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 at 19:40
|
show 5 more comments
This question already has an answer here:
Read a line-oriented file which may not end with a newline
6 answers
#!/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.)
shell-script
This question already has an answer here:
Read a line-oriented file which may not end with a newline
6 answers
#!/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.)
This question already has an answer here:
Read a line-oriented file which may not end with a newline
6 answers
shell-script
shell-script
edited Feb 18 at 19:34
Cesa Salaam
asked Feb 18 at 19:18
Cesa SalaamCesa Salaam
11
11
 marked as duplicate by Kusalananda
 StackExchange.ready(function() 
 if (StackExchange.options.isMobile) return;
 $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() 
 var $hover = $(this).addClass('hover-bound'),
 $msg = $hover.siblings('.dupe-hammer-message');
 $hover.hover(
 function() 
 $hover.showInfoMessage('', 
 messageElement: $msg.clone().show(),
 transient: false,
 position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
 dismissable: false,
 relativeToBody: true
 );
 ,
 function() 
 StackExchange.helpers.removeMessages();
 
 );
 );
 );
 Feb 18 at 19:36
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
 marked as duplicate by Kusalananda
 StackExchange.ready(function() 
 if (StackExchange.options.isMobile) return;
 $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() 
 var $hover = $(this).addClass('hover-bound'),
 $msg = $hover.siblings('.dupe-hammer-message');
 $hover.hover(
 function() 
 $hover.showInfoMessage('', 
 messageElement: $msg.clone().show(),
 transient: false,
 position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
 dismissable: false,
 relativeToBody: true
 );
 ,
 function() 
 StackExchange.helpers.removeMessages();
 
 );
 );
 );
 Feb 18 at 19:36
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Please add a sample of the contents ofnumbers.txt. The filename suffix means nothing on Unix systems. Both.shand.txtfiles are just text files.
– Kusalananda
Feb 18 at 19:26
I added a screen shot of both files
– Cesa Salaam
Feb 18 at 19:29
2
Please, don't post images of text.
– Kusalananda
Feb 18 at 19:32
1
Your file does not contain a single terminated line.readcan only read complete lines.
– Kusalananda
Feb 18 at 19:33
1
I guess it would be more correct to say thatreadreads 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 at 19:40
|
show 5 more comments
Please add a sample of the contents ofnumbers.txt. The filename suffix means nothing on Unix systems. Both.shand.txtfiles are just text files.
– Kusalananda
Feb 18 at 19:26
I added a screen shot of both files
– Cesa Salaam
Feb 18 at 19:29
2
Please, don't post images of text.
– Kusalananda
Feb 18 at 19:32
1
Your file does not contain a single terminated line.readcan only read complete lines.
– Kusalananda
Feb 18 at 19:33
1
I guess it would be more correct to say thatreadreads 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 at 19:40
Please add a sample of the contents of
numbers.txt. The filename suffix means nothing on Unix systems. Both .sh and .txt files are just text files.– Kusalananda
Feb 18 at 19:26
Please add a sample of the contents of
numbers.txt. The filename suffix means nothing on Unix systems. Both .sh and .txt files are just text files.– Kusalananda
Feb 18 at 19:26
I added a screen shot of both files
– Cesa Salaam
Feb 18 at 19:29
I added a screen shot of both files
– Cesa Salaam
Feb 18 at 19:29
2
2
Please, don't post images of text.
– Kusalananda
Feb 18 at 19:32
Please, don't post images of text.
– Kusalananda
Feb 18 at 19:32
1
1
Your file does not contain a single terminated line.
read can only read complete lines.– Kusalananda
Feb 18 at 19:33
Your file does not contain a single terminated line.
read can only read complete lines.– Kusalananda
Feb 18 at 19:33
1
1
I guess it would be more correct to say that
read reads the line (and assigns it to variable p) but returns false, having encountered EOF while doing so: hence the body of the while loop is not executed.– steeldriver
Feb 18 at 19:40
I guess it would be more correct to say that
read reads the line (and assigns it to variable p) but returns false, having encountered EOF while doing so: hence the body of the while loop is not executed.– steeldriver
Feb 18 at 19:40
|
show 5 more comments
 1 Answer
 1
 
active
oldest
votes
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
$
my apologies. I forgot to edit that ou, I was just testing something there. But even when changing to echo "$p", nothing prints
– Cesa Salaam
Feb 18 at 19:24
@CesaSalaam It works for me, are you sure that numbers.txt file is not empty?
– Matej
Feb 18 at 19:27
add a comment |
 1 Answer
 1
 
active
oldest
votes
 1 Answer
 1
 
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
$
my apologies. I forgot to edit that ou, I was just testing something there. But even when changing to echo "$p", nothing prints
– Cesa Salaam
Feb 18 at 19:24
@CesaSalaam It works for me, are you sure that numbers.txt file is not empty?
– Matej
Feb 18 at 19:27
add a comment |
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
$
my apologies. I forgot to edit that ou, I was just testing something there. But even when changing to echo "$p", nothing prints
– Cesa Salaam
Feb 18 at 19:24
@CesaSalaam It works for me, are you sure that numbers.txt file is not empty?
– Matej
Feb 18 at 19:27
add a comment |
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
$
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
$
edited Feb 18 at 19:26
answered Feb 18 at 19:22
MatejMatej
2068
2068
my apologies. I forgot to edit that ou, I was just testing something there. But even when changing to echo "$p", nothing prints
– Cesa Salaam
Feb 18 at 19:24
@CesaSalaam It works for me, are you sure that numbers.txt file is not empty?
– Matej
Feb 18 at 19:27
add a comment |
my apologies. I forgot to edit that ou, I was just testing something there. But even when changing to echo "$p", nothing prints
– Cesa Salaam
Feb 18 at 19:24
@CesaSalaam It works for me, are you sure that numbers.txt file is not empty?
– Matej
Feb 18 at 19:27
my apologies. I forgot to edit that ou, I was just testing something there. But even when changing to echo "$p", nothing prints
– Cesa Salaam
Feb 18 at 19:24
my apologies. I forgot to edit that ou, I was just testing something there. But even when changing to echo "$p", nothing prints
– Cesa Salaam
Feb 18 at 19:24
@CesaSalaam It works for me, are you sure that numbers.txt file is not empty?
– Matej
Feb 18 at 19:27
@CesaSalaam It works for me, are you sure that numbers.txt file is not empty?
– Matej
Feb 18 at 19:27
add a comment |
Please add a sample of the contents of
numbers.txt. The filename suffix means nothing on Unix systems. Both.shand.txtfiles are just text files.– Kusalananda
Feb 18 at 19:26
I added a screen shot of both files
– Cesa Salaam
Feb 18 at 19:29
2
Please, don't post images of text.
– Kusalananda
Feb 18 at 19:32
1
Your file does not contain a single terminated line.
readcan only read complete lines.– Kusalananda
Feb 18 at 19:33
1
I guess it would be more correct to say that
readreads 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 at 19:40