#!/bin/bash # grab the second line of the ouput produced by the command: free -g (displays output in Gb) secondLine=$(free | sed -n '2p') #echo $secondLine #split the string in secondLine into an array read -ra ADDR <<< "$secondLine" #get the total RAM from array totalRam="${ADDR[1]}" #get the used RAM from array usedRam="${ADDR[2]}" # calculate and display the percentage pct="$(($usedRam*100/$totalRam))" echo "$pct"