I'm not getting cube of the number












2















while [ "$c" = y -o "$c" = Y -o -z $c ]
do
echo enter a number;
read n;
if [ $n -ge 0 -a $n -le 50 ];then
echo "cube= `expr $n * $n * $n`";
fi;
echo y to continue or any to exit;
read c;
done









share|improve this question

























  • To ask a better question, you should describe (or better, show) what actually happens, and describe how that differs from what you want to happen.

    – glenn jackman
    Jan 11 at 21:02
















2















while [ "$c" = y -o "$c" = Y -o -z $c ]
do
echo enter a number;
read n;
if [ $n -ge 0 -a $n -le 50 ];then
echo "cube= `expr $n * $n * $n`";
fi;
echo y to continue or any to exit;
read c;
done









share|improve this question

























  • To ask a better question, you should describe (or better, show) what actually happens, and describe how that differs from what you want to happen.

    – glenn jackman
    Jan 11 at 21:02














2












2








2








while [ "$c" = y -o "$c" = Y -o -z $c ]
do
echo enter a number;
read n;
if [ $n -ge 0 -a $n -le 50 ];then
echo "cube= `expr $n * $n * $n`";
fi;
echo y to continue or any to exit;
read c;
done









share|improve this question
















while [ "$c" = y -o "$c" = Y -o -z $c ]
do
echo enter a number;
read n;
if [ $n -ge 0 -a $n -le 50 ];then
echo "cube= `expr $n * $n * $n`";
fi;
echo y to continue or any to exit;
read c;
done






shell files






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 11 at 19:52









fra-san

1,4051215




1,4051215










asked Jan 11 at 19:31









Parth PrajapatiParth Prajapati

111




111













  • To ask a better question, you should describe (or better, show) what actually happens, and describe how that differs from what you want to happen.

    – glenn jackman
    Jan 11 at 21:02



















  • To ask a better question, you should describe (or better, show) what actually happens, and describe how that differs from what you want to happen.

    – glenn jackman
    Jan 11 at 21:02

















To ask a better question, you should describe (or better, show) what actually happens, and describe how that differs from what you want to happen.

– glenn jackman
Jan 11 at 21:02





To ask a better question, you should describe (or better, show) what actually happens, and describe how that differs from what you want to happen.

– glenn jackman
Jan 11 at 21:02










2 Answers
2






active

oldest

votes


















6














You've got a few problems with your shell script. First, you should quote $c in the while (all of them — you missed the last one). Otherwise, when $c is empty (say, at the start of your program), the -z test gets passed nothing instead of the empty string, giving an error (something along the lines of "argument expected").



Second, you need to escape the * in your expr command. Otherwise it's trying to do a glob (match filenames), just like cat * would do. Easiest is to escape it to *. The error from that will depend on exactly what the * happens to expand to (i.e., which files are in your current directory), but will probably be something confusing!



That should at least get your script to run.



PS: There are a bunch more ways this could be improved, you might want to check out ShellCheck for some (automated) suggestions.






share|improve this answer































    1














    In bash, you could write:



    PS3="Continue? "
    while true; do

    read -p "Enter a number: " n
    ((0 <= n && n <= 50)) && echo "cube = $((n * n * n))"

    select ans in yes no; do
    case $ans in
    yes) break ;;
    no) break 2 ;;
    esac
    done
    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%2f494006%2fim-not-getting-cube-of-the-number%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      6














      You've got a few problems with your shell script. First, you should quote $c in the while (all of them — you missed the last one). Otherwise, when $c is empty (say, at the start of your program), the -z test gets passed nothing instead of the empty string, giving an error (something along the lines of "argument expected").



      Second, you need to escape the * in your expr command. Otherwise it's trying to do a glob (match filenames), just like cat * would do. Easiest is to escape it to *. The error from that will depend on exactly what the * happens to expand to (i.e., which files are in your current directory), but will probably be something confusing!



      That should at least get your script to run.



      PS: There are a bunch more ways this could be improved, you might want to check out ShellCheck for some (automated) suggestions.






      share|improve this answer




























        6














        You've got a few problems with your shell script. First, you should quote $c in the while (all of them — you missed the last one). Otherwise, when $c is empty (say, at the start of your program), the -z test gets passed nothing instead of the empty string, giving an error (something along the lines of "argument expected").



        Second, you need to escape the * in your expr command. Otherwise it's trying to do a glob (match filenames), just like cat * would do. Easiest is to escape it to *. The error from that will depend on exactly what the * happens to expand to (i.e., which files are in your current directory), but will probably be something confusing!



        That should at least get your script to run.



        PS: There are a bunch more ways this could be improved, you might want to check out ShellCheck for some (automated) suggestions.






        share|improve this answer


























          6












          6








          6







          You've got a few problems with your shell script. First, you should quote $c in the while (all of them — you missed the last one). Otherwise, when $c is empty (say, at the start of your program), the -z test gets passed nothing instead of the empty string, giving an error (something along the lines of "argument expected").



          Second, you need to escape the * in your expr command. Otherwise it's trying to do a glob (match filenames), just like cat * would do. Easiest is to escape it to *. The error from that will depend on exactly what the * happens to expand to (i.e., which files are in your current directory), but will probably be something confusing!



          That should at least get your script to run.



          PS: There are a bunch more ways this could be improved, you might want to check out ShellCheck for some (automated) suggestions.






          share|improve this answer













          You've got a few problems with your shell script. First, you should quote $c in the while (all of them — you missed the last one). Otherwise, when $c is empty (say, at the start of your program), the -z test gets passed nothing instead of the empty string, giving an error (something along the lines of "argument expected").



          Second, you need to escape the * in your expr command. Otherwise it's trying to do a glob (match filenames), just like cat * would do. Easiest is to escape it to *. The error from that will depend on exactly what the * happens to expand to (i.e., which files are in your current directory), but will probably be something confusing!



          That should at least get your script to run.



          PS: There are a bunch more ways this could be improved, you might want to check out ShellCheck for some (automated) suggestions.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 11 at 19:43









          derobertderobert

          73k8154210




          73k8154210

























              1














              In bash, you could write:



              PS3="Continue? "
              while true; do

              read -p "Enter a number: " n
              ((0 <= n && n <= 50)) && echo "cube = $((n * n * n))"

              select ans in yes no; do
              case $ans in
              yes) break ;;
              no) break 2 ;;
              esac
              done
              done





              share|improve this answer




























                1














                In bash, you could write:



                PS3="Continue? "
                while true; do

                read -p "Enter a number: " n
                ((0 <= n && n <= 50)) && echo "cube = $((n * n * n))"

                select ans in yes no; do
                case $ans in
                yes) break ;;
                no) break 2 ;;
                esac
                done
                done





                share|improve this answer


























                  1












                  1








                  1







                  In bash, you could write:



                  PS3="Continue? "
                  while true; do

                  read -p "Enter a number: " n
                  ((0 <= n && n <= 50)) && echo "cube = $((n * n * n))"

                  select ans in yes no; do
                  case $ans in
                  yes) break ;;
                  no) break 2 ;;
                  esac
                  done
                  done





                  share|improve this answer













                  In bash, you could write:



                  PS3="Continue? "
                  while true; do

                  read -p "Enter a number: " n
                  ((0 <= n && n <= 50)) && echo "cube = $((n * n * n))"

                  select ans in yes no; do
                  case $ans in
                  yes) break ;;
                  no) break 2 ;;
                  esac
                  done
                  done






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 11 at 21:01









                  glenn jackmanglenn jackman

                  51.1k571110




                  51.1k571110






























                      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%2f494006%2fim-not-getting-cube-of-the-number%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

                      Mario Kart Wii

                      What does “Dominus providebit” mean?

                      Antonio Litta Visconti Arese