20 lines
581 B
Bash
Executable File
20 lines
581 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Create an empty array to store random numbers
|
|
random_numbers=()
|
|
|
|
# As long as the length of the array is less than 5, continue to loop
|
|
while [ ${#random_numbers[@]} -lt 5 ]
|
|
do
|
|
# Get a random number; ask the user if they want to add it to the array
|
|
random_number=$RANDOM
|
|
read -p "Add $random_number to the list? (y/n): " choice
|
|
|
|
# If the user chose "y", add the random number to the array
|
|
if [ "$choice" = "y" ]; then random_numbers+=($random_number); fi
|
|
done
|
|
|
|
# Show the contents of the array
|
|
echo "Random Numbers: ${random_numbers[@]}"
|
|
|