I would like to fill a simply array in bash inside a while loop.
I try to do this :
read -p " Value : " nb
declare -a array
while [[ $nb != "s" ]]
do
read -p " Value : " nb
array+=("$nb")
done
echo ${array[@]}
If I try with 1,2,3,4 and 5 as values, the output is :
Value : 1
Value : 2
Value : 3
Value : 4
Value : 5 ( to stop the loop and display the array )
2 3 4 5 s
Or, I wan this output :
Value : 1
Value : 2
Value : 3
Value : 4
Value : 5
Value : s
1 2 3 4 5
Can you tell me what is wrong in my script ?
read, then it does an append, and then it goes up to to do the test to decide if it should run the loop again. Thus, the append happens whether or not that test would succeed.whileloop, or Python's, or Java's, etc.