Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Perform an action on a list/array of variables from user input in bash

    Hi all

    I've a bash script to read user input and perform a task on it. But what id like is for the user to be able to enter a list and perform the action on each of the list for as many as are entered.

    echo -n "Enter the list"

    read list
    a_script text[a-c]

    hope that makes sense...

    can anyone help?

  2. #2
    Solved courtesy of David the H @

    for information...

    echo 'Enter your array elements one at a time, followed by newlines.'
    echo 'Type "exit" to finish.'

    while read -r input ; do

    [[ $input == exit ]] && break
    array+=( "$input" )


    echo 'You entered the following array elements:'

    printf '%s\n' "${array[@]}"

    cheers Dave.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts