0

Currently, I'm working on a Bash script that would allow for an infinite amount of input from the user.

Currently, I have the script running only with a specific number of variables.

I'm using the following line:

read var1 var2 var3

My goal is to have it so that the user can input as many variables into the script without having to add a bunch of variables

3
  • i think what you want is a variable number of inputs. see this answer for more info stackoverflow.com/questions/10307280/… Commented Apr 6, 2018 at 20:57
  • 2
    Use an array: read -a vars. Ask for help if you need assistance with arrays. Commented Apr 6, 2018 at 20:58
  • 1
    Infinite? How do you test that? Commented Apr 6, 2018 at 21:51

1 Answer 1

0

Example of use

read -a var # see help -m read

echo "${#var[@]} inputs in array \$var with indexes: ${!var[@]}"
echo "inputs: ${var[@]}"
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.