**MY WEEK THREE (3) EXPERIENCE AT BLOCKFUSE LABS
This week has been quite challenging as we delved deeper into understanding Logic and having the right "thought-process" towards writing and executing bash scripts.
We dwelt on learning the concepts and logic behind "for-loop" and "while-loop" and we understand that these loops have a broad range of applications as they are used widely to profer solutions to given problems.
We used the while loop to write a bash script that simulated the processes of starting , driving and stoping a car. This is what mine looks like:
#!/bin/bash
echo "Welcome Driver, enter the name of your Car"
read COMMAND
echo "AVAILABLE COMMANDS"
echo "Start: to start engine"
echo "Stop: to stop engine"
echo "help: to display directions"
SHOULD_EXECUTE=true
ENGINE_ON=false
while true;
$SHOULD_EXECUTE;
do
echo "Enter 'Command' to operate"
read COMMAND
if [[ $COMMAND == "Start" && $ENGINE_ON == false ]];
then
echo "Starting Engine"
echo "Engine started and running"
ENGINE_ON=true
echo "Select Drive Mode"
echo "Type 'help' to promt guide"
elif [[ $COMMAND == "help" && $ENGINE_ON == true ]];
elif [[ $COMMAND == "help" && $ENGINE_ON == true ]];
then
echo "Engage gear"
echo "D: for Drive"
echo "R: for reverse"
echo "P: for park"
read COMMAND
elif [[ $COMMAND == "D" && $ENGINE_ON == true ]];
then
echo "Drive Mode"
echo "Moving forward"
COMMAND=D
elif [[ $COMMAND == "D" && $ENGINE_ON == true ]];then
echo "Drive gear already engaged"
elif [[ $COMMAND == "R" && $ENGINE_ON ]];
then
echo "Reverse Mode"
echo "Moving Backwards"
elif [[ $COMMAND == "P" && $ENGINE_ON ]];
then
echo "Parking Mode"
echo "Parking gear engaged"
echo "type 'OFF' to turn of engine"
ENGINE_ON=false
echo "Reached your destination?"
echo "type 'OFF' to turn off engine:"
read COMMAND
elif [[ $COMMAND == "OFF" && $ENGINE_0N ]];
then
echo "Welcome to Your new destination"
echo "type 'exit' to exit your Car"
read COMMAND
elif [[ $COMMAND == "exit" ]];
then
echo "GOODBYE BOSS"
break
fi
done
Thankyou Blockfuse.