Zsh: test newline in case
Clash 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-@'
zsh
add a comment |Â
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-@'
zsh
add a comment |Â
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-@'
zsh
# 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
zsh
edited Sep 13 at 12:16
JdeBP
29.7k461136
29.7k461136
asked Sep 13 at 9:35
Tuyen Pham
30510
30510
add a comment |Â
add a comment |Â
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
I usedvared -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, withvared
that I mentioned above I'd like to capture that user input isenter
or not? ifenter
echo something. Because-c
I believe the variable is create if not exist. I only check forenter
not an empty input likespace
.
â Tuyen Pham
Sep 13 at 11:45
@TuyenPham, it's still unclear what you want. "Enter" invared
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 wanta=y; vared -p "input something: " a
â Stéphane Chazelas
Sep 13 at 15:07
 |Â
show 2 more comments
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
I usedvared -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, withvared
that I mentioned above I'd like to capture that user input isenter
or not? ifenter
echo something. Because-c
I believe the variable is create if not exist. I only check forenter
not an empty input likespace
.
â Tuyen Pham
Sep 13 at 11:45
@TuyenPham, it's still unclear what you want. "Enter" invared
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 wanta=y; vared -p "input something: " a
â Stéphane Chazelas
Sep 13 at 15:07
 |Â
show 2 more comments
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
I usedvared -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, withvared
that I mentioned above I'd like to capture that user input isenter
or not? ifenter
echo something. Because-c
I believe the variable is create if not exist. I only check forenter
not an empty input likespace
.
â Tuyen Pham
Sep 13 at 11:45
@TuyenPham, it's still unclear what you want. "Enter" invared
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 wanta=y; vared -p "input something: " a
â Stéphane Chazelas
Sep 13 at 15:07
 |Â
show 2 more comments
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
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
edited Sep 13 at 15:42
answered Sep 13 at 9:45
Stéphane Chazelas
286k53528867
286k53528867
I usedvared -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, withvared
that I mentioned above I'd like to capture that user input isenter
or not? ifenter
echo something. Because-c
I believe the variable is create if not exist. I only check forenter
not an empty input likespace
.
â Tuyen Pham
Sep 13 at 11:45
@TuyenPham, it's still unclear what you want. "Enter" invared
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 wanta=y; vared -p "input something: " a
â Stéphane Chazelas
Sep 13 at 15:07
 |Â
show 2 more comments
I usedvared -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, withvared
that I mentioned above I'd like to capture that user input isenter
or not? ifenter
echo something. Because-c
I believe the variable is create if not exist. I only check forenter
not an empty input likespace
.
â Tuyen Pham
Sep 13 at 11:45
@TuyenPham, it's still unclear what you want. "Enter" invared
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 wanta=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
 |Â
show 2 more comments
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password