Differenze tra le versioni di "Gestione degli array in console Windows"
(Creata pagina con "← Torna a Windows Category:Windows dichiarazione arr=(Hello World) Assegnazione singola: arr[0]=Hello arr[1]=Wor...") |
|||
| (Una versione intermedia di uno stesso utente non è mostrata) | |||
| Riga 8: | Riga 8: | ||
Lettura: | Lettura: | ||
echo ${arr[0]} ${arr[1]} | echo ${arr[0]} ${arr[1]} | ||
| − | |||
| − | |||
<pre> | <pre> | ||
#!/bin/bash | #!/bin/bash | ||
| Riga 25: | Riga 23: | ||
${#arr[*]} # Number of items in the array | ${#arr[*]} # Number of items in the array | ||
${#arr[0]} # Length of item zero | ${#arr[0]} # Length of item zero | ||
| − | |||
Esempi: | Esempi: | ||
<pre> | <pre> | ||
Versione attuale delle 15:28, 11 ago 2023
dichiarazione
arr=(Hello World)
Assegnazione singola:
arr[0]=Hello arr[1]=World
Lettura:
echo ${arr[0]} ${arr[1]}
#!/bin/bash
# Dichiarazione array di stringhe
arrVar=("AC" "TV" "Mobile" "Fridge" "Oven" "Blender")
# Aggiunta di un elemento
arrVar+=("Dish Washer")
Lettura:
${arr[*]} # All of the items in the array
${!arr[*]} # All of the indexes in the array
${#arr[*]} # Number of items in the array
${#arr[0]} # Length of item zero
Esempi:
array=(one two three four [5]=five)
echo "Array size: ${#array[*]}"
echo "Array items:"
for item in ${array[*]}
do
printf " %s\n" $item
done
echo "Array indexes:"
for index in ${!array[*]}
do
printf " %d\n" $index
done
echo "Array items and indexes:"
for index in ${!array[*]}
do
printf "%4d: %s\n" $index ${array[$index]}
done
Risultato
Array size: 5 Array items: one two three four five Array indexes: 0 1 2 3 5 Array items and indexes: 0: one 1: two 2: three 3: four 5: five
fonti: