I want to get an input from the user using read
read line
and the proper input would be a string and then a number:
a 5
b 6
+ 87
How do you separate the “a” and 5 into two variables, with the 5 into a integer variable?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I suggest reading the documenentation of
readto get you started:Here are the first two paragraphs:
Note that bash doesn’t have a notion of “integer variables” comparable to other programming languages. Bash variables are untyped. Declaring a variable as integer using
declare -ionly influences assignments to this variable — everything that is not a valid integer is silently set to0.