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

  • i think what you want is a variable number of inputs. see this answer for more info https://stackoverflow.com/questions/10307280/how-to-define-a-shell-script-with-variable-number-of-arguments – aensm Apr 06 '18 at 20:57
  • 2
    Use an array: `read -a vars`. Ask for help if you need assistance with arrays. – glenn jackman Apr 06 '18 at 20:58
  • 1
    Infinite? How do you test that? – stark Apr 06 '18 at 21:51

1 Answers1

0

Example of use

read -a var # see help -m read

echo "${#var[@]} inputs in array \$var with indexes: ${!var[@]}"
echo "inputs: ${var[@]}"
kyodev
  • 563
  • 2
  • 14