Write a bash script to set up an array called colors of at l

Write a bash script to set up an array called \"colors\" of at least 5 different color names that you choose. Also define a variable called \"favorite\", and set that to one of the color names. Then go through the array with a loop, and print them, one by one. If the current color name matches \"favorite\", print that color with an asterisk on either side of the name. Use an \"if\" statement to check.

Solution

#!/bin/bash

#set up an array called \"colors\" of at least 5 different color names
colors=(Blue Red Violet White Black Orange Green)

#set a variable called \"favorite\" to one of the color names
favorite=Violet;

#loop through colors
#current color name matches \"favorite\", then
# print that color with an asterisk on either side of the name
for i in ${colors[@]} ;
do
if [ $i == $favorite ]; then
echo \"*$favorite*\"
fi
echo $i
done

Write a bash script to set up an array called \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site