Files
hpr_website/www/eps/hpr2719/hpr2719_bash17_ex2.sh

36 lines
697 B
Bash
Executable File

#!/bin/bash
#-------------------------------------------------------------------------------
# Example 2 for Bash Tips show 17: Array concatenation
#-------------------------------------------------------------------------------
#
# Make three indexed arrays
#
declare -a a1 a2 a3
#
# Seed the random number generator
#
RANDOM=$(date +%N)
#
# Place 10 random numbers between 1..100 into the arrays a1 and a2
#
for ((i=1; i<=10; i++)); do
a1+=( $(( ( RANDOM % 100 ) + 1 )) )
a2+=( $(( ( RANDOM % 100 ) + 1 )) )
done
#
# Show the results
#
echo "a1: ${a1[*]}"
echo "a2: ${a2[*]}"
#
# Concatenate a1 and a2 into a3 and show the result
#
a3=( "${a1[@]}" "${a2[@]}" )
echo "a3: ${a3[*]}"