Clear it in 3 steps
Start the environment
Investigate the target
Submit the flag

This script has several intentional bugs (typos, syntax mistakes) and fails to run to completion. Use bash's debugging features to fix them one by one.
bash -x scriptname shows an execution trace
Error messages hint at the line number
Also check for syntax errors like a missing fi to close an if block