My ultimate goal is to fill an array with user inputted positive and negative numbers. This script I wrote is very limited, but it should give you an idea of what I am trying to do. Basically, I ask how many numbers and then reserve 3 spaces for each number (two for the number and one for the white space in between). But this forces the user to input single digit numbers with a 0 in front (01, 02, 03...) and if the number is negative or more than 2 digits, this script wont reserve the correct space. I am sure there is a better way to do this so feel free to scrap this code if you can think of a better way. It should be able to handle any number of numbers and any size number.

echo How many numbers in your sequence?
read n


echo Please enter your sequence separated by spaces
echo \(single digit numbers should be in the form 01, 02, 03...\)
echo Example sequence: 12 -14 03 09 -19

read -n $n C
7 Years
Discussion Span
Last Post by Mattpd

Sorry for the nube question, I was just misusing read. The -a option works wonders!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.