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

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












0
















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.)










share|improve this question















marked as duplicate by Kusalananda shell-script
Users with the  shell-script badge can single-handedly close shell-script questions as duplicates and reopen them as needed.

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 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






  • 2





    Please, don't post images of text.

    – Kusalananda
    Feb 18 at 19:32






  • 1





    Your file does not contain a single terminated line. read can only read complete lines.

    – Kusalananda
    Feb 18 at 19:33






  • 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















0
















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.)










share|improve this question















marked as duplicate by Kusalananda shell-script
Users with the  shell-script badge can single-handedly close shell-script questions as duplicates and reopen them as needed.

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 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






  • 2





    Please, don't post images of text.

    – Kusalananda
    Feb 18 at 19:32






  • 1





    Your file does not contain a single terminated line. read can only read complete lines.

    – Kusalananda
    Feb 18 at 19:33






  • 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













0












0








0









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.)










share|improve this question

















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 18 at 19:34







Cesa Salaam

















asked Feb 18 at 19:18









Cesa SalaamCesa Salaam

11




11




marked as duplicate by Kusalananda shell-script
Users with the  shell-script badge can single-handedly close shell-script questions as duplicates and reopen them as needed.

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 shell-script
Users with the  shell-script badge can single-handedly close shell-script questions as duplicates and reopen them as needed.

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 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






  • 2





    Please, don't post images of text.

    – Kusalananda
    Feb 18 at 19:32






  • 1





    Your file does not contain a single terminated line. read can only read complete lines.

    – Kusalananda
    Feb 18 at 19:33






  • 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

















  • 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






  • 2





    Please, don't post images of text.

    – Kusalananda
    Feb 18 at 19:32






  • 1





    Your file does not contain a single terminated line. read can only read complete lines.

    – Kusalananda
    Feb 18 at 19:33






  • 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
















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










1 Answer
1






active

oldest

votes


















0














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
$





share|improve this answer

























  • 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

















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














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
$





share|improve this answer

























  • 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















0














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
$





share|improve this answer

























  • 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













0












0








0







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
$





share|improve this answer















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
$






share|improve this answer














share|improve this answer



share|improve this answer








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

















  • 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


Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?