# Possible Syntax Error - Bash Scripting Basics - Guided Exercise

**URL:** <https://forums.cybrary.it/t/possible-syntax-error-bash-scripting-basics-guided-exercise/450726>\
**Category:** IT and Cybersecurity Foundations\
**Created:** [March 29, 2025, 7:06am UTC](https://forums.cybrary.it/t/possible-syntax-error-bash-scripting-basics-guided-exercise/450726 "2025-03-29T07:06:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![root0shell0](https://forums.cybrary.it/user_avatar/forums.cybrary.it/root0shell0/32/11_2.png) [@root0shell0](https://forums.cybrary.it/u/root0shell0)\
**Post date:** [March 29, 2025, 7:06am UTC](https://forums.cybrary.it/t/possible-syntax-error-bash-scripting-basics-guided-exercise/450726/1 "2025-03-29T07:06:23Z")

</div>

# Part 3: Reusable Scripts of 18.

#!/bin/bash

#Create the fruits array from the fruits text file  
mapfile -t fruits \< “fruits.txt”

#Assign variables based on the fruits array’s length  
arrayLength=${#fruits[@]}

firstFruit=0  
lastFruit=$((arrayLength-1))

#Print array facts to the screen

echo “There are $arrayLength fruits in the array.”  
echo “The first fruit is ${fruits[$firstFruit]}.”  
echo “The last fruit is ${fruits[$lastFruit]}.”

#Compare every fruit in the fruits array to “melon”  
for $fruit in ${fruits[@]}  
do  
if [$fruit != “melon”]  
then  
echo “I love $fruit!”  
else  
echo “Yuck, $fruit.”  
fi  
done

for $fruit in ${fruits[@]} it should be for fruit in ${fruits[@]}

and melons instead of melon  
if goal is to only add comments without chaning the code.

---

<div class="post-metadata">

**Author:** ![JosephWhite](https://forums.cybrary.it/user_avatar/forums.cybrary.it/josephwhite/32/2407_2.png) [@JosephWhite](https://forums.cybrary.it/u/JosephWhite)\
**Post date:** [March 29, 2025, 3:24pm UTC](https://forums.cybrary.it/t/possible-syntax-error-bash-scripting-basics-guided-exercise/450726/2 "2025-03-29T15:24:07Z")

</div>

Thank you so much for pointing this out!!! ❤❤❤

I have fixed the fruit and melons 🙂
