From: Einar Jørgen Haraldseid Date: Mon, 12 Jun 2017 12:49:31 +0000 (+0200) Subject: Bedre måte å vite array-størrelsen X-Git-Url: https://git.slaskete.net/einar-bin/commitdiff_plain/f485c3303a579bd4f135730164d9a0dd22d8f646?ds=sidebyside Bedre måte å vite array-størrelsen --- diff --git a/middag.sh b/middag.sh index 9f2b66b..dbb0e14 100755 --- a/middag.sh +++ b/middag.sh @@ -24,28 +24,13 @@ Sides=( 'salat' ) -PrepCount=0 -while [ "x${Prep[PrepCount]}" != "x" ]; do - ((PrepCount++)) -done - -MeatCount=0 -while [ "x${Meat[MeatCount]}" != "x" ]; do - ((MeatCount++)) -done - -SideCount=0 -while [ "x${Sides[SideCount]}" != "x" ]; do - ((SideCount++)) -done - PrepN=$RANDOM -(( PrepN %= $PrepCount )) +(( PrepN %= ${#Prep[@]} )) MeatN=$RANDOM -(( MeatN %= $MeatCount )) +(( MeatN %= ${#Meat[@]} )) SideN=$RANDOM -(( SideN %= $SideCount )) +(( SideN %= ${#Sides[@]} )) echo "${Prep[PrepN]} ${Meat[MeatN]} med ${Sides[SideN]}"