Home » , » Bash

Bash

-->


This page mainly focuses on the syntax of bash.


use of array

#!/bin/bash

# We create an example array 'a' containing 16 values:
# array a = ( 0 1 2 3 4 ... 14 15 )
a=({0..15})

echo 'Linear array:'
echo ${a[*]}
echo "a specified dimension." 
echo ${a[5]}

# We now display this array 'a' in a 4x4 grid
echo 'Matrix array:'
for row in {1..4}; do
    for col in {1..4}; do
        echo -n ${a[((4*row+col-5))]}$'\t'
    done
    echo
done


Popular Posts