L
L
Lizard2019-01-14 04:15:30
bash
Lizard, 2019-01-14 04:15:30

How to write input values ​​to variables?

Hello. I have a piece of script:

#elif [ "$a" == more ]; then 
  read -p "Number of ports: " select
    for (( i = 0; i < $select; i++ )); do
      read -p "Input ports: " input
    done

The user enters a certain number into the select variable.
I need to ask the user for the port number as many times as he specified in select, and add his answers to variables.
How to implement it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Q
q2zoff, 2019-01-14
@rootovich1

read -p "Number of ports: "

for (( i = 0; i < $REPLY; i++ ))
do
    read -p "Input port: " ports[i]
done

echo ${ports[@]}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question