Use of ` <` in bash script gives (standard_in) 1: syntax error

Multi tool use
Multi tool use












0















I'm getting this error as output



(standard_in) 1: syntax error
something something
something something


when i want is



something something
something something


Below is the bash script. After much trial and error checks i found the error is because of this line



done < /home/afsara/Desktop/ns2_offline/ns_code/wired.out;



What am I possibly doing wrong here?



    #!/bin/bash 

cd /
cd /home/afsara/Desktop/ns2_offline/ns_code/

#INPUT: output file AND number of iterations
output_file_format="tcp";
iteration_float=2.0;

end=5


iteration=$(printf %.0f $iteration_float);

r=5

while [ $r -le $end ]
do
###############################START A ROUND
l=1;thr=0.0;val=0.0

i=0
while [ $i -lt $iteration ]
do

while read val
do
dir="/home/afsara/Desktop/ns2_offline/ns_code/"
#dir=""
under="_"
all="all"
output_file="$dir$output_file_format$under$r$under$r$under$all.out"

echo -ne "Throughput: $thr " > $output_file


if [ $l == '1' ]; then
thr=$(echo "scale=5; $thr+$val/$iteration_float" | bc )
echo -ne "throughput: $val " >> $output_file
fi


echo "$val"
done < /home/afsara/Desktop/ns2_offline/ns_code/wired.out; #problem because of this

i=$(($i+1))
l=0
#################END AN ITERATION
done

r=$(($r+1))
#######################################END A ROUND
done









share|improve this question




















  • 1





    bash and sh are not the same. Which do you intend to run this under? Add a shebang line to specify.

    – Dan Farrell
    Dec 31 '18 at 18:54











  • Running your code through shellcheck.net and fixing the issues it identifies is a good place to start. Beyond that, before ask a question, you need to build a minimal reproducer -- in addition to the MCVE link above, see "Tricks for Trimming" at sscce.org

    – Charles Duffy
    Dec 31 '18 at 19:07








  • 1





    Frankly, the error message you posted looks like one that would come from bc, not from bash. Using bash -x yourscript to run it with tracing would help you identify where the problem is (and thus ask a narrower question).

    – Charles Duffy
    Dec 31 '18 at 19:09








  • 1





    As an aside, consider [ "$l" = 1 ] -- there's no reason to quote the constant on the right-hand side, but if you don't quote the expansion on the left it can get expanded to multiple words or no words at all. Making sure it's always exactly one word lets test give you better error messages (we have way too many questions from people who are confused by something that expands to [ = 1 ] giving an error about = not being a unary operator).

    – Charles Duffy
    Dec 31 '18 at 19:52











  • And = is guaranteed to work with all POSIX-compliant versions of test, whereas == is a nonportable extension; see pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html

    – Charles Duffy
    Dec 31 '18 at 19:53
















0















I'm getting this error as output



(standard_in) 1: syntax error
something something
something something


when i want is



something something
something something


Below is the bash script. After much trial and error checks i found the error is because of this line



done < /home/afsara/Desktop/ns2_offline/ns_code/wired.out;



What am I possibly doing wrong here?



    #!/bin/bash 

cd /
cd /home/afsara/Desktop/ns2_offline/ns_code/

#INPUT: output file AND number of iterations
output_file_format="tcp";
iteration_float=2.0;

end=5


iteration=$(printf %.0f $iteration_float);

r=5

while [ $r -le $end ]
do
###############################START A ROUND
l=1;thr=0.0;val=0.0

i=0
while [ $i -lt $iteration ]
do

while read val
do
dir="/home/afsara/Desktop/ns2_offline/ns_code/"
#dir=""
under="_"
all="all"
output_file="$dir$output_file_format$under$r$under$r$under$all.out"

echo -ne "Throughput: $thr " > $output_file


if [ $l == '1' ]; then
thr=$(echo "scale=5; $thr+$val/$iteration_float" | bc )
echo -ne "throughput: $val " >> $output_file
fi


echo "$val"
done < /home/afsara/Desktop/ns2_offline/ns_code/wired.out; #problem because of this

i=$(($i+1))
l=0
#################END AN ITERATION
done

r=$(($r+1))
#######################################END A ROUND
done









share|improve this question




















  • 1





    bash and sh are not the same. Which do you intend to run this under? Add a shebang line to specify.

    – Dan Farrell
    Dec 31 '18 at 18:54











  • Running your code through shellcheck.net and fixing the issues it identifies is a good place to start. Beyond that, before ask a question, you need to build a minimal reproducer -- in addition to the MCVE link above, see "Tricks for Trimming" at sscce.org

    – Charles Duffy
    Dec 31 '18 at 19:07








  • 1





    Frankly, the error message you posted looks like one that would come from bc, not from bash. Using bash -x yourscript to run it with tracing would help you identify where the problem is (and thus ask a narrower question).

    – Charles Duffy
    Dec 31 '18 at 19:09








  • 1





    As an aside, consider [ "$l" = 1 ] -- there's no reason to quote the constant on the right-hand side, but if you don't quote the expansion on the left it can get expanded to multiple words or no words at all. Making sure it's always exactly one word lets test give you better error messages (we have way too many questions from people who are confused by something that expands to [ = 1 ] giving an error about = not being a unary operator).

    – Charles Duffy
    Dec 31 '18 at 19:52











  • And = is guaranteed to work with all POSIX-compliant versions of test, whereas == is a nonportable extension; see pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html

    – Charles Duffy
    Dec 31 '18 at 19:53














0












0








0








I'm getting this error as output



(standard_in) 1: syntax error
something something
something something


when i want is



something something
something something


Below is the bash script. After much trial and error checks i found the error is because of this line



done < /home/afsara/Desktop/ns2_offline/ns_code/wired.out;



What am I possibly doing wrong here?



    #!/bin/bash 

cd /
cd /home/afsara/Desktop/ns2_offline/ns_code/

#INPUT: output file AND number of iterations
output_file_format="tcp";
iteration_float=2.0;

end=5


iteration=$(printf %.0f $iteration_float);

r=5

while [ $r -le $end ]
do
###############################START A ROUND
l=1;thr=0.0;val=0.0

i=0
while [ $i -lt $iteration ]
do

while read val
do
dir="/home/afsara/Desktop/ns2_offline/ns_code/"
#dir=""
under="_"
all="all"
output_file="$dir$output_file_format$under$r$under$r$under$all.out"

echo -ne "Throughput: $thr " > $output_file


if [ $l == '1' ]; then
thr=$(echo "scale=5; $thr+$val/$iteration_float" | bc )
echo -ne "throughput: $val " >> $output_file
fi


echo "$val"
done < /home/afsara/Desktop/ns2_offline/ns_code/wired.out; #problem because of this

i=$(($i+1))
l=0
#################END AN ITERATION
done

r=$(($r+1))
#######################################END A ROUND
done









share|improve this question
















I'm getting this error as output



(standard_in) 1: syntax error
something something
something something


when i want is



something something
something something


Below is the bash script. After much trial and error checks i found the error is because of this line



done < /home/afsara/Desktop/ns2_offline/ns_code/wired.out;



What am I possibly doing wrong here?



    #!/bin/bash 

cd /
cd /home/afsara/Desktop/ns2_offline/ns_code/

#INPUT: output file AND number of iterations
output_file_format="tcp";
iteration_float=2.0;

end=5


iteration=$(printf %.0f $iteration_float);

r=5

while [ $r -le $end ]
do
###############################START A ROUND
l=1;thr=0.0;val=0.0

i=0
while [ $i -lt $iteration ]
do

while read val
do
dir="/home/afsara/Desktop/ns2_offline/ns_code/"
#dir=""
under="_"
all="all"
output_file="$dir$output_file_format$under$r$under$r$under$all.out"

echo -ne "Throughput: $thr " > $output_file


if [ $l == '1' ]; then
thr=$(echo "scale=5; $thr+$val/$iteration_float" | bc )
echo -ne "throughput: $val " >> $output_file
fi


echo "$val"
done < /home/afsara/Desktop/ns2_offline/ns_code/wired.out; #problem because of this

i=$(($i+1))
l=0
#################END AN ITERATION
done

r=$(($r+1))
#######################################END A ROUND
done






bash






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 31 '18 at 18:58







afsara_ben

















asked Dec 31 '18 at 18:50









afsara_benafsara_ben

337




337








  • 1





    bash and sh are not the same. Which do you intend to run this under? Add a shebang line to specify.

    – Dan Farrell
    Dec 31 '18 at 18:54











  • Running your code through shellcheck.net and fixing the issues it identifies is a good place to start. Beyond that, before ask a question, you need to build a minimal reproducer -- in addition to the MCVE link above, see "Tricks for Trimming" at sscce.org

    – Charles Duffy
    Dec 31 '18 at 19:07








  • 1





    Frankly, the error message you posted looks like one that would come from bc, not from bash. Using bash -x yourscript to run it with tracing would help you identify where the problem is (and thus ask a narrower question).

    – Charles Duffy
    Dec 31 '18 at 19:09








  • 1





    As an aside, consider [ "$l" = 1 ] -- there's no reason to quote the constant on the right-hand side, but if you don't quote the expansion on the left it can get expanded to multiple words or no words at all. Making sure it's always exactly one word lets test give you better error messages (we have way too many questions from people who are confused by something that expands to [ = 1 ] giving an error about = not being a unary operator).

    – Charles Duffy
    Dec 31 '18 at 19:52











  • And = is guaranteed to work with all POSIX-compliant versions of test, whereas == is a nonportable extension; see pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html

    – Charles Duffy
    Dec 31 '18 at 19:53














  • 1





    bash and sh are not the same. Which do you intend to run this under? Add a shebang line to specify.

    – Dan Farrell
    Dec 31 '18 at 18:54











  • Running your code through shellcheck.net and fixing the issues it identifies is a good place to start. Beyond that, before ask a question, you need to build a minimal reproducer -- in addition to the MCVE link above, see "Tricks for Trimming" at sscce.org

    – Charles Duffy
    Dec 31 '18 at 19:07








  • 1





    Frankly, the error message you posted looks like one that would come from bc, not from bash. Using bash -x yourscript to run it with tracing would help you identify where the problem is (and thus ask a narrower question).

    – Charles Duffy
    Dec 31 '18 at 19:09








  • 1





    As an aside, consider [ "$l" = 1 ] -- there's no reason to quote the constant on the right-hand side, but if you don't quote the expansion on the left it can get expanded to multiple words or no words at all. Making sure it's always exactly one word lets test give you better error messages (we have way too many questions from people who are confused by something that expands to [ = 1 ] giving an error about = not being a unary operator).

    – Charles Duffy
    Dec 31 '18 at 19:52











  • And = is guaranteed to work with all POSIX-compliant versions of test, whereas == is a nonportable extension; see pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html

    – Charles Duffy
    Dec 31 '18 at 19:53








1




1





bash and sh are not the same. Which do you intend to run this under? Add a shebang line to specify.

– Dan Farrell
Dec 31 '18 at 18:54





bash and sh are not the same. Which do you intend to run this under? Add a shebang line to specify.

– Dan Farrell
Dec 31 '18 at 18:54













Running your code through shellcheck.net and fixing the issues it identifies is a good place to start. Beyond that, before ask a question, you need to build a minimal reproducer -- in addition to the MCVE link above, see "Tricks for Trimming" at sscce.org

– Charles Duffy
Dec 31 '18 at 19:07







Running your code through shellcheck.net and fixing the issues it identifies is a good place to start. Beyond that, before ask a question, you need to build a minimal reproducer -- in addition to the MCVE link above, see "Tricks for Trimming" at sscce.org

– Charles Duffy
Dec 31 '18 at 19:07






1




1





Frankly, the error message you posted looks like one that would come from bc, not from bash. Using bash -x yourscript to run it with tracing would help you identify where the problem is (and thus ask a narrower question).

– Charles Duffy
Dec 31 '18 at 19:09







Frankly, the error message you posted looks like one that would come from bc, not from bash. Using bash -x yourscript to run it with tracing would help you identify where the problem is (and thus ask a narrower question).

– Charles Duffy
Dec 31 '18 at 19:09






1




1





As an aside, consider [ "$l" = 1 ] -- there's no reason to quote the constant on the right-hand side, but if you don't quote the expansion on the left it can get expanded to multiple words or no words at all. Making sure it's always exactly one word lets test give you better error messages (we have way too many questions from people who are confused by something that expands to [ = 1 ] giving an error about = not being a unary operator).

– Charles Duffy
Dec 31 '18 at 19:52





As an aside, consider [ "$l" = 1 ] -- there's no reason to quote the constant on the right-hand side, but if you don't quote the expansion on the left it can get expanded to multiple words or no words at all. Making sure it's always exactly one word lets test give you better error messages (we have way too many questions from people who are confused by something that expands to [ = 1 ] giving an error about = not being a unary operator).

– Charles Duffy
Dec 31 '18 at 19:52













And = is guaranteed to work with all POSIX-compliant versions of test, whereas == is a nonportable extension; see pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html

– Charles Duffy
Dec 31 '18 at 19:53





And = is guaranteed to work with all POSIX-compliant versions of test, whereas == is a nonportable extension; see pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html

– Charles Duffy
Dec 31 '18 at 19:53












1 Answer
1






active

oldest

votes


















0














That's a bc error message, not a bash error message. It has nothing whatsoever to do with the done < /home/afsara/Desktop/ns2_offline/ns_code/wired.out, except perhaps that if you remove the redirection the loop has no input so its contents don't run at all.






share|improve this answer


























  • yes i thought so at first. but i ran the if part separately, and it didn't give any errors. If i remove < /home/afsara/Desktop/ns2_offline/ns_code/wired.out then the code works fine

    – afsara_ben
    Dec 31 '18 at 19:16






  • 1





    The < makes your input come from the file, so something in the file is causing bc to fail later. As I suggested earlier, use set -x to log what bash is doing, so you can see what arguments it passes to bc when you have the val read from the file.

    – Charles Duffy
    Dec 31 '18 at 19:30








  • 1





    It could be, for example, that your file has DOS newlines in it -- that would lead to val values that bc doesn't know how to parse.

    – Charles Duffy
    Dec 31 '18 at 19:31













  • yes that was it!

    – afsara_ben
    Dec 31 '18 at 19:40






  • 1





    Ahh. (For the record, the sigils at the front indicate nesting depth, so the number you have tells how many functions/etc. the current scope is inside of).

    – Charles Duffy
    Dec 31 '18 at 19:47











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53990549%2fuse-of-in-bash-script-gives-standard-in-1-syntax-error%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














That's a bc error message, not a bash error message. It has nothing whatsoever to do with the done < /home/afsara/Desktop/ns2_offline/ns_code/wired.out, except perhaps that if you remove the redirection the loop has no input so its contents don't run at all.






share|improve this answer


























  • yes i thought so at first. but i ran the if part separately, and it didn't give any errors. If i remove < /home/afsara/Desktop/ns2_offline/ns_code/wired.out then the code works fine

    – afsara_ben
    Dec 31 '18 at 19:16






  • 1





    The < makes your input come from the file, so something in the file is causing bc to fail later. As I suggested earlier, use set -x to log what bash is doing, so you can see what arguments it passes to bc when you have the val read from the file.

    – Charles Duffy
    Dec 31 '18 at 19:30








  • 1





    It could be, for example, that your file has DOS newlines in it -- that would lead to val values that bc doesn't know how to parse.

    – Charles Duffy
    Dec 31 '18 at 19:31













  • yes that was it!

    – afsara_ben
    Dec 31 '18 at 19:40






  • 1





    Ahh. (For the record, the sigils at the front indicate nesting depth, so the number you have tells how many functions/etc. the current scope is inside of).

    – Charles Duffy
    Dec 31 '18 at 19:47
















0














That's a bc error message, not a bash error message. It has nothing whatsoever to do with the done < /home/afsara/Desktop/ns2_offline/ns_code/wired.out, except perhaps that if you remove the redirection the loop has no input so its contents don't run at all.






share|improve this answer


























  • yes i thought so at first. but i ran the if part separately, and it didn't give any errors. If i remove < /home/afsara/Desktop/ns2_offline/ns_code/wired.out then the code works fine

    – afsara_ben
    Dec 31 '18 at 19:16






  • 1





    The < makes your input come from the file, so something in the file is causing bc to fail later. As I suggested earlier, use set -x to log what bash is doing, so you can see what arguments it passes to bc when you have the val read from the file.

    – Charles Duffy
    Dec 31 '18 at 19:30








  • 1





    It could be, for example, that your file has DOS newlines in it -- that would lead to val values that bc doesn't know how to parse.

    – Charles Duffy
    Dec 31 '18 at 19:31













  • yes that was it!

    – afsara_ben
    Dec 31 '18 at 19:40






  • 1





    Ahh. (For the record, the sigils at the front indicate nesting depth, so the number you have tells how many functions/etc. the current scope is inside of).

    – Charles Duffy
    Dec 31 '18 at 19:47














0












0








0







That's a bc error message, not a bash error message. It has nothing whatsoever to do with the done < /home/afsara/Desktop/ns2_offline/ns_code/wired.out, except perhaps that if you remove the redirection the loop has no input so its contents don't run at all.






share|improve this answer















That's a bc error message, not a bash error message. It has nothing whatsoever to do with the done < /home/afsara/Desktop/ns2_offline/ns_code/wired.out, except perhaps that if you remove the redirection the loop has no input so its contents don't run at all.







share|improve this answer














share|improve this answer



share|improve this answer








answered Dec 31 '18 at 19:10


























community wiki





Charles Duffy














  • yes i thought so at first. but i ran the if part separately, and it didn't give any errors. If i remove < /home/afsara/Desktop/ns2_offline/ns_code/wired.out then the code works fine

    – afsara_ben
    Dec 31 '18 at 19:16






  • 1





    The < makes your input come from the file, so something in the file is causing bc to fail later. As I suggested earlier, use set -x to log what bash is doing, so you can see what arguments it passes to bc when you have the val read from the file.

    – Charles Duffy
    Dec 31 '18 at 19:30








  • 1





    It could be, for example, that your file has DOS newlines in it -- that would lead to val values that bc doesn't know how to parse.

    – Charles Duffy
    Dec 31 '18 at 19:31













  • yes that was it!

    – afsara_ben
    Dec 31 '18 at 19:40






  • 1





    Ahh. (For the record, the sigils at the front indicate nesting depth, so the number you have tells how many functions/etc. the current scope is inside of).

    – Charles Duffy
    Dec 31 '18 at 19:47



















  • yes i thought so at first. but i ran the if part separately, and it didn't give any errors. If i remove < /home/afsara/Desktop/ns2_offline/ns_code/wired.out then the code works fine

    – afsara_ben
    Dec 31 '18 at 19:16






  • 1





    The < makes your input come from the file, so something in the file is causing bc to fail later. As I suggested earlier, use set -x to log what bash is doing, so you can see what arguments it passes to bc when you have the val read from the file.

    – Charles Duffy
    Dec 31 '18 at 19:30








  • 1





    It could be, for example, that your file has DOS newlines in it -- that would lead to val values that bc doesn't know how to parse.

    – Charles Duffy
    Dec 31 '18 at 19:31













  • yes that was it!

    – afsara_ben
    Dec 31 '18 at 19:40






  • 1





    Ahh. (For the record, the sigils at the front indicate nesting depth, so the number you have tells how many functions/etc. the current scope is inside of).

    – Charles Duffy
    Dec 31 '18 at 19:47

















yes i thought so at first. but i ran the if part separately, and it didn't give any errors. If i remove < /home/afsara/Desktop/ns2_offline/ns_code/wired.out then the code works fine

– afsara_ben
Dec 31 '18 at 19:16





yes i thought so at first. but i ran the if part separately, and it didn't give any errors. If i remove < /home/afsara/Desktop/ns2_offline/ns_code/wired.out then the code works fine

– afsara_ben
Dec 31 '18 at 19:16




1




1





The < makes your input come from the file, so something in the file is causing bc to fail later. As I suggested earlier, use set -x to log what bash is doing, so you can see what arguments it passes to bc when you have the val read from the file.

– Charles Duffy
Dec 31 '18 at 19:30







The < makes your input come from the file, so something in the file is causing bc to fail later. As I suggested earlier, use set -x to log what bash is doing, so you can see what arguments it passes to bc when you have the val read from the file.

– Charles Duffy
Dec 31 '18 at 19:30






1




1





It could be, for example, that your file has DOS newlines in it -- that would lead to val values that bc doesn't know how to parse.

– Charles Duffy
Dec 31 '18 at 19:31







It could be, for example, that your file has DOS newlines in it -- that would lead to val values that bc doesn't know how to parse.

– Charles Duffy
Dec 31 '18 at 19:31















yes that was it!

– afsara_ben
Dec 31 '18 at 19:40





yes that was it!

– afsara_ben
Dec 31 '18 at 19:40




1




1





Ahh. (For the record, the sigils at the front indicate nesting depth, so the number you have tells how many functions/etc. the current scope is inside of).

– Charles Duffy
Dec 31 '18 at 19:47





Ahh. (For the record, the sigils at the front indicate nesting depth, so the number you have tells how many functions/etc. the current scope is inside of).

– Charles Duffy
Dec 31 '18 at 19:47




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53990549%2fuse-of-in-bash-script-gives-standard-in-1-syntax-error%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







7KQ 6 zZPxgI,0 hn4dChMgkqmdiDLshNUzKkRjhH T18rTpv47RC,mqSnHYqeJ,EQ0
HpJ8y0rOACd,Ho3H5R4OVwKh IrsYlULXpz6MQQDf cpSXI9YNEjs7J,r4,e,hhubNAfFWNuISQKXk4

Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas