Bash Scripting
Objective
The objective of this task is to create a Bash script that reads the contents of a protected file and displays the result in the terminal.
Procedure
Open the TryHackMe room and connect to the target machine through SSH, following the room instructions.
Locate the files read_secret.sh and secret.txt.
Open read_secret.sh in a text editor or with a command such as cat.
Write a Bash script that reads the contents of secret.txt, stores the content in a variable, and prints the variable on the terminal.
Give the script the appropriate permission and execute it.
Submit the required screenshots showing the TryHackMe answer and the script/output.
Bash Script
The script used in the task reads secret.txt with cat, stores its contents in the variable secret, and then prints the value using echo.
Get Sourabh Jala’s stories in your inbox
Join Medium for free to get updates from this writer.
#!/bin/bash
secret=$(cat secret.txt)
echo “$secret”
Screenshot: Script Content
Execution and Result
After creating the script, the task instructions require appropriate permission to be given to the script and then the related file to be executed. In the submitted terminal screenshot, the command output reveals the task flag.
Flag
Flag{you_wrote_an_script}
Conclusion
This task demonstrates a basic Bash scripting workflow: locating files, reading file content with a command, storing the output in a variable, and displaying that variable in the terminal. It also provides practical experience with executing scripts in a Linux environment.







