Zsh: test newline in case

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











up vote
0
down vote

favorite












# user input a here
vared -p "input something" -c a
case $a 'n']) echo something;;


won't work, can someone give an insight?



I'm trying to test against user input that if contain y or an enter - newline, echo something.



EDIT:



set | grep IFS
IFS=$' tnC-@'









share|improve this question



























    up vote
    0
    down vote

    favorite












    # user input a here
    vared -p "input something" -c a
    case $a 'n']) echo something;;


    won't work, can someone give an insight?



    I'm trying to test against user input that if contain y or an enter - newline, echo something.



    EDIT:



    set | grep IFS
    IFS=$' tnC-@'









    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      # user input a here
      vared -p "input something" -c a
      case $a 'n']) echo something;;


      won't work, can someone give an insight?



      I'm trying to test against user input that if contain y or an enter - newline, echo something.



      EDIT:



      set | grep IFS
      IFS=$' tnC-@'









      share|improve this question















      # user input a here
      vared -p "input something" -c a
      case $a 'n']) echo something;;


      won't work, can someone give an insight?



      I'm trying to test against user input that if contain y or an enter - newline, echo something.



      EDIT:



      set | grep IFS
      IFS=$' tnC-@'






      zsh






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 13 at 12:16









      JdeBP

      29.7k461136




      29.7k461136










      asked Sep 13 at 9:35









      Tuyen Pham

      30510




      30510




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          You're not saying how you're getting user input.



          With read:



          read -k 'answer?Are you OK? '
          case $answer in
          (y | Y | $'n') echo 1;;
          # or ([$'yYn']) echo 1;;
          (*) echo 2;;
          esac


          But if you're using read without -k or vared and want to detect when the user presses Enter without entering any answer, that's when you would want to test for an empty value:



          answer=; vared -p 'Are you OK? ' answer
          case $answer in
          (y | Y | "") echo 1;;
          # or ([yY] | "") echo 1;;
          (*) echo 2;;
          esac


          Or seed the answer with y (though the user would have to do BackspaceN to say no):



          answer=y; vared -p 'Are you OK? ' answer
          case $answer in
          (y | Y) echo 1;;
          (*) echo 2;;
          esac





          share|improve this answer






















          • I used vared -p "input something" -c a to get input, I don't think your answer works for me. Did I miss something?
            – Tuyen Pham
            Sep 13 at 9:54










          • @TuyenPham, vared is to edit the content of a variable. To get a newline character into that variable, the user would have to type Ctrl+V Ctrl+J, or Alt+Enter, is that really what you want? Or do you want to check whether the user has entered an empty input (like when they press Enter when the editing buffer is empty)?
            – Stéphane Chazelas
            Sep 13 at 11:40










          • Yes, with vared that I mentioned above I'd like to capture that user input is enter or not? if enter echo something. Because -c I believe the variable is create if not exist. I only check for enter not an empty input like space.
            – Tuyen Pham
            Sep 13 at 11:45










          • @TuyenPham, it's still unclear what you want. "Enter" in vared is for accepting the current value. You also need to press "Enter" after having edited the variable value so as to contain "y" or "n" (for instance by pressing "y" or "n" if the variable was initially empty). Pressing space adds a space character to the content of the variable, it makes it non-empty. Do you want to check that the user didn't modify the value of the variable?
            – Stéphane Chazelas
            Sep 13 at 12:38






          • 1




            @TuenPham, sounds like you want a=y; vared -p "input something: " a
            – Stéphane Chazelas
            Sep 13 at 15:07










          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',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          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%2f468754%2fzsh-test-newline-in-case%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          You're not saying how you're getting user input.



          With read:



          read -k 'answer?Are you OK? '
          case $answer in
          (y | Y | $'n') echo 1;;
          # or ([$'yYn']) echo 1;;
          (*) echo 2;;
          esac


          But if you're using read without -k or vared and want to detect when the user presses Enter without entering any answer, that's when you would want to test for an empty value:



          answer=; vared -p 'Are you OK? ' answer
          case $answer in
          (y | Y | "") echo 1;;
          # or ([yY] | "") echo 1;;
          (*) echo 2;;
          esac


          Or seed the answer with y (though the user would have to do BackspaceN to say no):



          answer=y; vared -p 'Are you OK? ' answer
          case $answer in
          (y | Y) echo 1;;
          (*) echo 2;;
          esac





          share|improve this answer






















          • I used vared -p "input something" -c a to get input, I don't think your answer works for me. Did I miss something?
            – Tuyen Pham
            Sep 13 at 9:54










          • @TuyenPham, vared is to edit the content of a variable. To get a newline character into that variable, the user would have to type Ctrl+V Ctrl+J, or Alt+Enter, is that really what you want? Or do you want to check whether the user has entered an empty input (like when they press Enter when the editing buffer is empty)?
            – Stéphane Chazelas
            Sep 13 at 11:40










          • Yes, with vared that I mentioned above I'd like to capture that user input is enter or not? if enter echo something. Because -c I believe the variable is create if not exist. I only check for enter not an empty input like space.
            – Tuyen Pham
            Sep 13 at 11:45










          • @TuyenPham, it's still unclear what you want. "Enter" in vared is for accepting the current value. You also need to press "Enter" after having edited the variable value so as to contain "y" or "n" (for instance by pressing "y" or "n" if the variable was initially empty). Pressing space adds a space character to the content of the variable, it makes it non-empty. Do you want to check that the user didn't modify the value of the variable?
            – Stéphane Chazelas
            Sep 13 at 12:38






          • 1




            @TuenPham, sounds like you want a=y; vared -p "input something: " a
            – Stéphane Chazelas
            Sep 13 at 15:07














          up vote
          1
          down vote



          accepted










          You're not saying how you're getting user input.



          With read:



          read -k 'answer?Are you OK? '
          case $answer in
          (y | Y | $'n') echo 1;;
          # or ([$'yYn']) echo 1;;
          (*) echo 2;;
          esac


          But if you're using read without -k or vared and want to detect when the user presses Enter without entering any answer, that's when you would want to test for an empty value:



          answer=; vared -p 'Are you OK? ' answer
          case $answer in
          (y | Y | "") echo 1;;
          # or ([yY] | "") echo 1;;
          (*) echo 2;;
          esac


          Or seed the answer with y (though the user would have to do BackspaceN to say no):



          answer=y; vared -p 'Are you OK? ' answer
          case $answer in
          (y | Y) echo 1;;
          (*) echo 2;;
          esac





          share|improve this answer






















          • I used vared -p "input something" -c a to get input, I don't think your answer works for me. Did I miss something?
            – Tuyen Pham
            Sep 13 at 9:54










          • @TuyenPham, vared is to edit the content of a variable. To get a newline character into that variable, the user would have to type Ctrl+V Ctrl+J, or Alt+Enter, is that really what you want? Or do you want to check whether the user has entered an empty input (like when they press Enter when the editing buffer is empty)?
            – Stéphane Chazelas
            Sep 13 at 11:40










          • Yes, with vared that I mentioned above I'd like to capture that user input is enter or not? if enter echo something. Because -c I believe the variable is create if not exist. I only check for enter not an empty input like space.
            – Tuyen Pham
            Sep 13 at 11:45










          • @TuyenPham, it's still unclear what you want. "Enter" in vared is for accepting the current value. You also need to press "Enter" after having edited the variable value so as to contain "y" or "n" (for instance by pressing "y" or "n" if the variable was initially empty). Pressing space adds a space character to the content of the variable, it makes it non-empty. Do you want to check that the user didn't modify the value of the variable?
            – Stéphane Chazelas
            Sep 13 at 12:38






          • 1




            @TuenPham, sounds like you want a=y; vared -p "input something: " a
            – Stéphane Chazelas
            Sep 13 at 15:07












          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          You're not saying how you're getting user input.



          With read:



          read -k 'answer?Are you OK? '
          case $answer in
          (y | Y | $'n') echo 1;;
          # or ([$'yYn']) echo 1;;
          (*) echo 2;;
          esac


          But if you're using read without -k or vared and want to detect when the user presses Enter without entering any answer, that's when you would want to test for an empty value:



          answer=; vared -p 'Are you OK? ' answer
          case $answer in
          (y | Y | "") echo 1;;
          # or ([yY] | "") echo 1;;
          (*) echo 2;;
          esac


          Or seed the answer with y (though the user would have to do BackspaceN to say no):



          answer=y; vared -p 'Are you OK? ' answer
          case $answer in
          (y | Y) echo 1;;
          (*) echo 2;;
          esac





          share|improve this answer














          You're not saying how you're getting user input.



          With read:



          read -k 'answer?Are you OK? '
          case $answer in
          (y | Y | $'n') echo 1;;
          # or ([$'yYn']) echo 1;;
          (*) echo 2;;
          esac


          But if you're using read without -k or vared and want to detect when the user presses Enter without entering any answer, that's when you would want to test for an empty value:



          answer=; vared -p 'Are you OK? ' answer
          case $answer in
          (y | Y | "") echo 1;;
          # or ([yY] | "") echo 1;;
          (*) echo 2;;
          esac


          Or seed the answer with y (though the user would have to do BackspaceN to say no):



          answer=y; vared -p 'Are you OK? ' answer
          case $answer in
          (y | Y) echo 1;;
          (*) echo 2;;
          esac






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Sep 13 at 15:42

























          answered Sep 13 at 9:45









          Stéphane Chazelas

          286k53528867




          286k53528867











          • I used vared -p "input something" -c a to get input, I don't think your answer works for me. Did I miss something?
            – Tuyen Pham
            Sep 13 at 9:54










          • @TuyenPham, vared is to edit the content of a variable. To get a newline character into that variable, the user would have to type Ctrl+V Ctrl+J, or Alt+Enter, is that really what you want? Or do you want to check whether the user has entered an empty input (like when they press Enter when the editing buffer is empty)?
            – Stéphane Chazelas
            Sep 13 at 11:40










          • Yes, with vared that I mentioned above I'd like to capture that user input is enter or not? if enter echo something. Because -c I believe the variable is create if not exist. I only check for enter not an empty input like space.
            – Tuyen Pham
            Sep 13 at 11:45










          • @TuyenPham, it's still unclear what you want. "Enter" in vared is for accepting the current value. You also need to press "Enter" after having edited the variable value so as to contain "y" or "n" (for instance by pressing "y" or "n" if the variable was initially empty). Pressing space adds a space character to the content of the variable, it makes it non-empty. Do you want to check that the user didn't modify the value of the variable?
            – Stéphane Chazelas
            Sep 13 at 12:38






          • 1




            @TuenPham, sounds like you want a=y; vared -p "input something: " a
            – Stéphane Chazelas
            Sep 13 at 15:07
















          • I used vared -p "input something" -c a to get input, I don't think your answer works for me. Did I miss something?
            – Tuyen Pham
            Sep 13 at 9:54










          • @TuyenPham, vared is to edit the content of a variable. To get a newline character into that variable, the user would have to type Ctrl+V Ctrl+J, or Alt+Enter, is that really what you want? Or do you want to check whether the user has entered an empty input (like when they press Enter when the editing buffer is empty)?
            – Stéphane Chazelas
            Sep 13 at 11:40










          • Yes, with vared that I mentioned above I'd like to capture that user input is enter or not? if enter echo something. Because -c I believe the variable is create if not exist. I only check for enter not an empty input like space.
            – Tuyen Pham
            Sep 13 at 11:45










          • @TuyenPham, it's still unclear what you want. "Enter" in vared is for accepting the current value. You also need to press "Enter" after having edited the variable value so as to contain "y" or "n" (for instance by pressing "y" or "n" if the variable was initially empty). Pressing space adds a space character to the content of the variable, it makes it non-empty. Do you want to check that the user didn't modify the value of the variable?
            – Stéphane Chazelas
            Sep 13 at 12:38






          • 1




            @TuenPham, sounds like you want a=y; vared -p "input something: " a
            – Stéphane Chazelas
            Sep 13 at 15:07















          I used vared -p "input something" -c a to get input, I don't think your answer works for me. Did I miss something?
          – Tuyen Pham
          Sep 13 at 9:54




          I used vared -p "input something" -c a to get input, I don't think your answer works for me. Did I miss something?
          – Tuyen Pham
          Sep 13 at 9:54












          @TuyenPham, vared is to edit the content of a variable. To get a newline character into that variable, the user would have to type Ctrl+V Ctrl+J, or Alt+Enter, is that really what you want? Or do you want to check whether the user has entered an empty input (like when they press Enter when the editing buffer is empty)?
          – Stéphane Chazelas
          Sep 13 at 11:40




          @TuyenPham, vared is to edit the content of a variable. To get a newline character into that variable, the user would have to type Ctrl+V Ctrl+J, or Alt+Enter, is that really what you want? Or do you want to check whether the user has entered an empty input (like when they press Enter when the editing buffer is empty)?
          – Stéphane Chazelas
          Sep 13 at 11:40












          Yes, with vared that I mentioned above I'd like to capture that user input is enter or not? if enter echo something. Because -c I believe the variable is create if not exist. I only check for enter not an empty input like space.
          – Tuyen Pham
          Sep 13 at 11:45




          Yes, with vared that I mentioned above I'd like to capture that user input is enter or not? if enter echo something. Because -c I believe the variable is create if not exist. I only check for enter not an empty input like space.
          – Tuyen Pham
          Sep 13 at 11:45












          @TuyenPham, it's still unclear what you want. "Enter" in vared is for accepting the current value. You also need to press "Enter" after having edited the variable value so as to contain "y" or "n" (for instance by pressing "y" or "n" if the variable was initially empty). Pressing space adds a space character to the content of the variable, it makes it non-empty. Do you want to check that the user didn't modify the value of the variable?
          – Stéphane Chazelas
          Sep 13 at 12:38




          @TuyenPham, it's still unclear what you want. "Enter" in vared is for accepting the current value. You also need to press "Enter" after having edited the variable value so as to contain "y" or "n" (for instance by pressing "y" or "n" if the variable was initially empty). Pressing space adds a space character to the content of the variable, it makes it non-empty. Do you want to check that the user didn't modify the value of the variable?
          – Stéphane Chazelas
          Sep 13 at 12:38




          1




          1




          @TuenPham, sounds like you want a=y; vared -p "input something: " a
          – Stéphane Chazelas
          Sep 13 at 15:07




          @TuenPham, sounds like you want a=y; vared -p "input something: " a
          – Stéphane Chazelas
          Sep 13 at 15:07

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f468754%2fzsh-test-newline-in-case%23new-answer', 'question_page');

          );

          Post as a guest













































































          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?