Loading…
OS · Arrays · Program 26 · In the record
Write a shell script to input the array elements and display it.
1#!/bin/bash2 3echo "Enter the number of elements:"4read n5 6echo "Enter $n elements:"7for (( i = 0; i < n; i++ ))8do9 read arr[i]10done11 12echo "The array elements are:"13for (( i = 0; i < n; i++ ))14do15 echo "arr[$i] = ${arr[i]}"16done5 ⏎ 10 ⏎ 20 ⏎ 30 ⏎ 40 ⏎ 50Enter the number of elements: 5 Enter 5 elements: 10 20 30 40 50 The array elements are: arr[0] = 10 arr[1] = 20 arr[2] = 30 arr[3] = 40 arr[4] = 50
Run program 26 in your browser
bash · just-bash. Change the code or the input, run it, break it, and see what happens.