Linux Bash Scripting Write a script that gives this outcome
Linux
Bash Scripting
Write a script that gives this outcome
Your script should first create an associative array called “student_marks”. Populate this array with marks obtained by 5 students( you can random five names and random marks for these five records). Once you have populated your array your script should display the student record stored in the array in the following format.
S.No Name Marks
1 ABC 40
2 CDE 45
3 EFG 34
4 GHI 22
5 IJK 20
Solution
declare -A student_marks # Or this line implicitly makes it an associative array (in global scope, bash 4.2+ only)
 student_marks[\"ABC\"]=40
 student_marks[\"CDE\"]=45
 student_marks[\"EFG\"]=34
 student_marks[\"GHI\"]=22
 student_marks[\"IJK\"]=20
 KEYS=(${!student_marks[@]})
 echo \"S.NO NAME MARKS\"
 for (( I=0; $I < ${#student_marks[@]}; I+=1 )); do let \"var=var+1\"; KEY=${KEYS[$I]}; echo $var---$KEY --- ${student_marks[$KEY]}; done

