How to count the number of arguments passed under condition?












0














I'm trying to create a shell script taking as argument a series of averages and assign for each note an observation, example :



There are 5 averages that are introduced.

There are 2 notes that are: pretty good.

There are 3 notes that are: well

....



for i in $@
if [[ $# -ge 16 ]];
then
let j++
echo " there are ${#j} notes that are : pretty good "
elif [[ $# -ge 14 ]];
let k++
echo " there are ${#k} notes that are : good "









share|improve this question




















  • 1




    Please try to format your question by editing it, using the formatting tools provided by U&L. If possible, code that's running would be helpful. Also, I am having a difficult time understanding your question. Can you maybe rephrase it?
    – OneK
    Dec 19 '18 at 9:25












  • Please don't post images of text or code! It makes it impossible to copy the code to an editor, and the reader can't control the colors, the font etc. That JPG with serious compression artifacts is especially hard to read. Just copy and paste the code itself, and make sure to format code in code blocks (see the editing help)
    – ilkkachu
    Dec 19 '18 at 10:01
















0














I'm trying to create a shell script taking as argument a series of averages and assign for each note an observation, example :



There are 5 averages that are introduced.

There are 2 notes that are: pretty good.

There are 3 notes that are: well

....



for i in $@
if [[ $# -ge 16 ]];
then
let j++
echo " there are ${#j} notes that are : pretty good "
elif [[ $# -ge 14 ]];
let k++
echo " there are ${#k} notes that are : good "









share|improve this question




















  • 1




    Please try to format your question by editing it, using the formatting tools provided by U&L. If possible, code that's running would be helpful. Also, I am having a difficult time understanding your question. Can you maybe rephrase it?
    – OneK
    Dec 19 '18 at 9:25












  • Please don't post images of text or code! It makes it impossible to copy the code to an editor, and the reader can't control the colors, the font etc. That JPG with serious compression artifacts is especially hard to read. Just copy and paste the code itself, and make sure to format code in code blocks (see the editing help)
    – ilkkachu
    Dec 19 '18 at 10:01














0












0








0







I'm trying to create a shell script taking as argument a series of averages and assign for each note an observation, example :



There are 5 averages that are introduced.

There are 2 notes that are: pretty good.

There are 3 notes that are: well

....



for i in $@
if [[ $# -ge 16 ]];
then
let j++
echo " there are ${#j} notes that are : pretty good "
elif [[ $# -ge 14 ]];
let k++
echo " there are ${#k} notes that are : good "









share|improve this question















I'm trying to create a shell script taking as argument a series of averages and assign for each note an observation, example :



There are 5 averages that are introduced.

There are 2 notes that are: pretty good.

There are 3 notes that are: well

....



for i in $@
if [[ $# -ge 16 ]];
then
let j++
echo " there are ${#j} notes that are : pretty good "
elif [[ $# -ge 14 ]];
let k++
echo " there are ${#k} notes that are : good "






shell-script shell scripting function






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 19 '18 at 12:18

























asked Dec 19 '18 at 9:17









Rania

61




61








  • 1




    Please try to format your question by editing it, using the formatting tools provided by U&L. If possible, code that's running would be helpful. Also, I am having a difficult time understanding your question. Can you maybe rephrase it?
    – OneK
    Dec 19 '18 at 9:25












  • Please don't post images of text or code! It makes it impossible to copy the code to an editor, and the reader can't control the colors, the font etc. That JPG with serious compression artifacts is especially hard to read. Just copy and paste the code itself, and make sure to format code in code blocks (see the editing help)
    – ilkkachu
    Dec 19 '18 at 10:01














  • 1




    Please try to format your question by editing it, using the formatting tools provided by U&L. If possible, code that's running would be helpful. Also, I am having a difficult time understanding your question. Can you maybe rephrase it?
    – OneK
    Dec 19 '18 at 9:25












  • Please don't post images of text or code! It makes it impossible to copy the code to an editor, and the reader can't control the colors, the font etc. That JPG with serious compression artifacts is especially hard to read. Just copy and paste the code itself, and make sure to format code in code blocks (see the editing help)
    – ilkkachu
    Dec 19 '18 at 10:01








1




1




Please try to format your question by editing it, using the formatting tools provided by U&L. If possible, code that's running would be helpful. Also, I am having a difficult time understanding your question. Can you maybe rephrase it?
– OneK
Dec 19 '18 at 9:25






Please try to format your question by editing it, using the formatting tools provided by U&L. If possible, code that's running would be helpful. Also, I am having a difficult time understanding your question. Can you maybe rephrase it?
– OneK
Dec 19 '18 at 9:25














Please don't post images of text or code! It makes it impossible to copy the code to an editor, and the reader can't control the colors, the font etc. That JPG with serious compression artifacts is especially hard to read. Just copy and paste the code itself, and make sure to format code in code blocks (see the editing help)
– ilkkachu
Dec 19 '18 at 10:01




Please don't post images of text or code! It makes it impossible to copy the code to an editor, and the reader can't control the colors, the font etc. That JPG with serious compression artifacts is especially hard to read. Just copy and paste the code itself, and make sure to format code in code blocks (see the editing help)
– ilkkachu
Dec 19 '18 at 10:01










1 Answer
1






active

oldest

votes


















0














Count your things first, then separately report the result:



#!/bin/bash

for a do
if (( a >= 10 && a < 12 )); then
pass=$(( pass + 1 ))
elif (( etc. for the other conditions ))
fi
done

printf '%d passedn' "$pass"


There is no need to test on $# as the loop (if written as above) would not execute at all if no arguments were passed.






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%2f489867%2fhow-to-count-the-number-of-arguments-passed-under-condition%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














    Count your things first, then separately report the result:



    #!/bin/bash

    for a do
    if (( a >= 10 && a < 12 )); then
    pass=$(( pass + 1 ))
    elif (( etc. for the other conditions ))
    fi
    done

    printf '%d passedn' "$pass"


    There is no need to test on $# as the loop (if written as above) would not execute at all if no arguments were passed.






    share|improve this answer


























      0














      Count your things first, then separately report the result:



      #!/bin/bash

      for a do
      if (( a >= 10 && a < 12 )); then
      pass=$(( pass + 1 ))
      elif (( etc. for the other conditions ))
      fi
      done

      printf '%d passedn' "$pass"


      There is no need to test on $# as the loop (if written as above) would not execute at all if no arguments were passed.






      share|improve this answer
























        0












        0








        0






        Count your things first, then separately report the result:



        #!/bin/bash

        for a do
        if (( a >= 10 && a < 12 )); then
        pass=$(( pass + 1 ))
        elif (( etc. for the other conditions ))
        fi
        done

        printf '%d passedn' "$pass"


        There is no need to test on $# as the loop (if written as above) would not execute at all if no arguments were passed.






        share|improve this answer












        Count your things first, then separately report the result:



        #!/bin/bash

        for a do
        if (( a >= 10 && a < 12 )); then
        pass=$(( pass + 1 ))
        elif (( etc. for the other conditions ))
        fi
        done

        printf '%d passedn' "$pass"


        There is no need to test on $# as the loop (if written as above) would not execute at all if no arguments were passed.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 19 '18 at 9:52









        Kusalananda

        121k16229372




        121k16229372






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f489867%2fhow-to-count-the-number-of-arguments-passed-under-condition%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

            Morgemoulin

            Scott Moir

            Souastre