How to use multiple variable for input with read command?

Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
I am using GNU bash - version 4.2.10(1).
I want to read multiple variables using single read command in shell script. So i tried as below:
echo " Enter P N R : "
read P N R
but it's not working. It just ask for single value of P variable and returns prompt.
I googled it but don't found any solution.
bash variable read
add a comment |Â
up vote
1
down vote
favorite
I am using GNU bash - version 4.2.10(1).
I want to read multiple variables using single read command in shell script. So i tried as below:
echo " Enter P N R : "
read P N R
but it's not working. It just ask for single value of P variable and returns prompt.
I googled it but don't found any solution.
bash variable read
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am using GNU bash - version 4.2.10(1).
I want to read multiple variables using single read command in shell script. So i tried as below:
echo " Enter P N R : "
read P N R
but it's not working. It just ask for single value of P variable and returns prompt.
I googled it but don't found any solution.
bash variable read
I am using GNU bash - version 4.2.10(1).
I want to read multiple variables using single read command in shell script. So i tried as below:
echo " Enter P N R : "
read P N R
but it's not working. It just ask for single value of P variable and returns prompt.
I googled it but don't found any solution.
bash variable read
asked Jul 30 at 7:26
Dip
183115
183115
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
read, without -r expects words on input to be delimited by the characters of the $IFS special parameter (by default SPC, TAB and NL, though as read reads only one line unless it ends in backslash, NL can't count) where backslash can be used to escape the separator or allow a line to be continued on the next physical line (backslash-newline sequences removed).
So, here the user must enter the values for P, N, R space or tab separated, like:
value_for_P value_for_N value_for_R
Or if the values can contain space:
value for P value for N value for R
(here we didn't bother escaping the spaces for R as the rest of the line after the third word would end-up in R anyway; the user would still need to escape a trailing space though).
If you want the user to enter the values on 3 lines, you'd need 3 read invocations. You'd then want -r to avoid the backslash processing and make IFS empty:
IFS= read -r P
IFS= read -r N
IFS= read -r R
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
read, without -r expects words on input to be delimited by the characters of the $IFS special parameter (by default SPC, TAB and NL, though as read reads only one line unless it ends in backslash, NL can't count) where backslash can be used to escape the separator or allow a line to be continued on the next physical line (backslash-newline sequences removed).
So, here the user must enter the values for P, N, R space or tab separated, like:
value_for_P value_for_N value_for_R
Or if the values can contain space:
value for P value for N value for R
(here we didn't bother escaping the spaces for R as the rest of the line after the third word would end-up in R anyway; the user would still need to escape a trailing space though).
If you want the user to enter the values on 3 lines, you'd need 3 read invocations. You'd then want -r to avoid the backslash processing and make IFS empty:
IFS= read -r P
IFS= read -r N
IFS= read -r R
add a comment |Â
up vote
2
down vote
accepted
read, without -r expects words on input to be delimited by the characters of the $IFS special parameter (by default SPC, TAB and NL, though as read reads only one line unless it ends in backslash, NL can't count) where backslash can be used to escape the separator or allow a line to be continued on the next physical line (backslash-newline sequences removed).
So, here the user must enter the values for P, N, R space or tab separated, like:
value_for_P value_for_N value_for_R
Or if the values can contain space:
value for P value for N value for R
(here we didn't bother escaping the spaces for R as the rest of the line after the third word would end-up in R anyway; the user would still need to escape a trailing space though).
If you want the user to enter the values on 3 lines, you'd need 3 read invocations. You'd then want -r to avoid the backslash processing and make IFS empty:
IFS= read -r P
IFS= read -r N
IFS= read -r R
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
read, without -r expects words on input to be delimited by the characters of the $IFS special parameter (by default SPC, TAB and NL, though as read reads only one line unless it ends in backslash, NL can't count) where backslash can be used to escape the separator or allow a line to be continued on the next physical line (backslash-newline sequences removed).
So, here the user must enter the values for P, N, R space or tab separated, like:
value_for_P value_for_N value_for_R
Or if the values can contain space:
value for P value for N value for R
(here we didn't bother escaping the spaces for R as the rest of the line after the third word would end-up in R anyway; the user would still need to escape a trailing space though).
If you want the user to enter the values on 3 lines, you'd need 3 read invocations. You'd then want -r to avoid the backslash processing and make IFS empty:
IFS= read -r P
IFS= read -r N
IFS= read -r R
read, without -r expects words on input to be delimited by the characters of the $IFS special parameter (by default SPC, TAB and NL, though as read reads only one line unless it ends in backslash, NL can't count) where backslash can be used to escape the separator or allow a line to be continued on the next physical line (backslash-newline sequences removed).
So, here the user must enter the values for P, N, R space or tab separated, like:
value_for_P value_for_N value_for_R
Or if the values can contain space:
value for P value for N value for R
(here we didn't bother escaping the spaces for R as the rest of the line after the third word would end-up in R anyway; the user would still need to escape a trailing space though).
If you want the user to enter the values on 3 lines, you'd need 3 read invocations. You'd then want -r to avoid the backslash processing and make IFS empty:
IFS= read -r P
IFS= read -r N
IFS= read -r R
edited Jul 30 at 8:47
answered Jul 30 at 7:36
Stéphane Chazelas
277k52511841
277k52511841
add a comment |Â
add a comment |Â
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%2f459267%2fhow-to-use-multiple-variable-for-input-with-read-command%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