For loop if statement syntax errorBash completion throwing syntax errorHow to turn verbose mode on and off using a case statement in UNIXFind MAPISend syntax and Replace with BLAT syntaxRename files in bash scriptSyntax error: Unterminated quoted string. Cannot find error“) Syntax error Invalid arithmetic operator (error token is ”syntax for tar + gunzip includedsyntax error near token ';'(homework)Syntax error near unexpected token `}' in a Bash function with an if-then statementUsing an if statement to see if files are in a folder using a wildcard

When do you stop "pushing" a book?

99th Percentile: top 1% or top 2%?

My perfect evil overlord plan... or is it?

Why is it wrong to *implement* myself a known, published, widely believed to be secure crypto algorithm?

Would encrypting a database protect against a compromised admin account?

Passport stamps art, can it be done?

Cryptography and elliptic curves

Why do unstable nuclei form?

An equation with two splits / differing alignments

Are there variations of the regular runtimes of the Big-O-Notation?

Is there any evidence that democracy is linked causatively with improved outcomes?

Is it bad writing or bad story telling if first person narrative contains more information than the narrator knows?

Program for finding longest run of zeros from a list of 100 random integers which are either 0 or 1

Has magnetic core memory been used beyond the Moon?

How to compare d20+x with advantage to d20+y without advantage (x < y)

Why can't I prove summation identities without guessing?

How did Arya survive this confrontation unscathed?

Company threw a surprise party for the CEO, 3 weeks later management says we have to pay for it, do I have to?

Need help replacing old cassette and chain

Is ‘despite that’ right?

Translation of the latin word 'sit' in Thomas Aquinas' works

Is there any evidence to support the claim that the United States was "suckered into WW1" by Zionists, made by Benjamin Freedman in his 1961 speech

Can 'sudo apt-get remove [write]' destroy my Ubuntu?

Is there an application which does HTTP PUT?



For loop if statement syntax error


Bash completion throwing syntax errorHow to turn verbose mode on and off using a case statement in UNIXFind MAPISend syntax and Replace with BLAT syntaxRename files in bash scriptSyntax error: Unterminated quoted string. Cannot find error“) Syntax error Invalid arithmetic operator (error token is ”syntax for tar + gunzip includedsyntax error near token ';'(homework)Syntax error near unexpected token `}' in a Bash function with an if-then statementUsing an if statement to see if files are in a folder using a wildcard






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have syntax error in my code to move files if the statement is true.The code goes on forever.Also tried adding quotes but unable to.I know there would be some silly mistake that I am doing.



for file in *.sort; 
do if [`wc -l` $i -eq 57817];
then mv "$i" "../$i";
fi; done


Any suggestions?










share|improve this question



















  • 5





    www.shellcheck.net

    – steeldriver
    4 hours ago

















0















I have syntax error in my code to move files if the statement is true.The code goes on forever.Also tried adding quotes but unable to.I know there would be some silly mistake that I am doing.



for file in *.sort; 
do if [`wc -l` $i -eq 57817];
then mv "$i" "../$i";
fi; done


Any suggestions?










share|improve this question



















  • 5





    www.shellcheck.net

    – steeldriver
    4 hours ago













0












0








0








I have syntax error in my code to move files if the statement is true.The code goes on forever.Also tried adding quotes but unable to.I know there would be some silly mistake that I am doing.



for file in *.sort; 
do if [`wc -l` $i -eq 57817];
then mv "$i" "../$i";
fi; done


Any suggestions?










share|improve this question
















I have syntax error in my code to move files if the statement is true.The code goes on forever.Also tried adding quotes but unable to.I know there would be some silly mistake that I am doing.



for file in *.sort; 
do if [`wc -l` $i -eq 57817];
then mv "$i" "../$i";
fi; done


Any suggestions?







linux shell-script






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 hours ago









Rui F Ribeiro

42.7k1486146




42.7k1486146










asked 4 hours ago









RonRon

4502614




4502614







  • 5





    www.shellcheck.net

    – steeldriver
    4 hours ago












  • 5





    www.shellcheck.net

    – steeldriver
    4 hours ago







5




5





www.shellcheck.net

– steeldriver
4 hours ago





www.shellcheck.net

– steeldriver
4 hours ago










1 Answer
1






active

oldest

votes


















6














  1. You need a space between [ and the conditions


  2. $i is not being set

  3. Your command substitution does not include the entire command (wc -l file is the entire command, you are only wrapping around wc -l)


  4. wc -l file will output the number of lines and the filename which will cause an error. wc -l <file could be used to avoid this

for file in *.sort; do 
if [ "$(wc -l <"$file")" -eq 57817 ]; then
mv "$file" "../$file"
fi
done





share|improve this answer

























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    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: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    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%2funix.stackexchange.com%2fquestions%2f518015%2ffor-loop-if-statement-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









    6














    1. You need a space between [ and the conditions


    2. $i is not being set

    3. Your command substitution does not include the entire command (wc -l file is the entire command, you are only wrapping around wc -l)


    4. wc -l file will output the number of lines and the filename which will cause an error. wc -l <file could be used to avoid this

    for file in *.sort; do 
    if [ "$(wc -l <"$file")" -eq 57817 ]; then
    mv "$file" "../$file"
    fi
    done





    share|improve this answer





























      6














      1. You need a space between [ and the conditions


      2. $i is not being set

      3. Your command substitution does not include the entire command (wc -l file is the entire command, you are only wrapping around wc -l)


      4. wc -l file will output the number of lines and the filename which will cause an error. wc -l <file could be used to avoid this

      for file in *.sort; do 
      if [ "$(wc -l <"$file")" -eq 57817 ]; then
      mv "$file" "../$file"
      fi
      done





      share|improve this answer



























        6












        6








        6







        1. You need a space between [ and the conditions


        2. $i is not being set

        3. Your command substitution does not include the entire command (wc -l file is the entire command, you are only wrapping around wc -l)


        4. wc -l file will output the number of lines and the filename which will cause an error. wc -l <file could be used to avoid this

        for file in *.sort; do 
        if [ "$(wc -l <"$file")" -eq 57817 ]; then
        mv "$file" "../$file"
        fi
        done





        share|improve this answer















        1. You need a space between [ and the conditions


        2. $i is not being set

        3. Your command substitution does not include the entire command (wc -l file is the entire command, you are only wrapping around wc -l)


        4. wc -l file will output the number of lines and the filename which will cause an error. wc -l <file could be used to avoid this

        for file in *.sort; do 
        if [ "$(wc -l <"$file")" -eq 57817 ]; then
        mv "$file" "../$file"
        fi
        done






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 4 hours ago

























        answered 4 hours ago









        Jesse_bJesse_b

        15k33574




        15k33574



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • 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%2funix.stackexchange.com%2fquestions%2f518015%2ffor-loop-if-statement-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







            Popular posts from this blog

            Siegen Nawigatsjuun

            Log på Navigationsmenu

            Log på Navigationsmenu