Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

creating a 2d array in a script in linux shell

#!/bin/bash
declare -A matrix
num_rows=4
num_columns=5

for ((i=1;i<=num_rows;i++)) do
    for ((j=1;j<=num_columns;j++)) do
        matrix[$i,$j]=$RANDOM
    done
done

f1="%$((${#num_rows}+1))s"
f2=" %9s"

printf "$f1" ''
for ((i=1;i<=num_rows;i++)) do
    printf "$f2" $i
done
echo

for ((j=1;j<=num_columns;j++)) do
    printf "$f1" $j
    for ((i=1;i<=num_rows;i++)) do
        printf "$f2" ${matrix[$i,$j]}
    done
    echo
done

Comment

PREVIOUS NEXT
Code Example
Shell :: generate certificate 
Shell :: install rabbitmq docker image 
Shell :: crear ramas git 
Shell :: change default branch github 
Shell :: powershell check if file exists 
Shell :: githum readme bold 
Shell :: mongodb install ubuntu 20.04 
Shell :: how to remove remote origin from git repo 
Shell :: open a pdf on linux 
Shell :: install aws cli v2 
Shell :: "GH001: Large files detected. You may want to try Git Large File Storage" error fix 
Shell :: docker compose up only one service 
Shell :: gtk windows install 
Shell :: create scheduled task via powershell scheduled reboot 
Shell :: how to install mono on ubuntui 
Shell :: macos clear terminal 
Shell :: how to install react spring with typescript 
Shell :: clear the git stash 
Shell :: extract tar.gz 
Shell :: powershell restart computer 
Shell :: install docker ec2 
Shell :: undo merge 
Shell :: git merge example 
Shell :: list files in git 
Shell :: ubuntu create directory with permissions 
Shell :: create new docker image from existing 
Shell :: Reading state information... Done E: Unable to locate package docker-ce 
Shell :: check how many container running or not running in docker 
Shell :: how to install apt 
Shell :: add flathub repository fedora 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =