Tryhackme - Bash Scripting

Tryhackme – Bash Scripting

In this walkthrough, we will be going through Bash Scripting room by Tryhackme. This covers the basics of bash scripting covering topics like variables, parameters and some test scripts to work on. After completing this room, you will be able to develop basic scripts in bash which can help you in automating the mundane tasks related to cyber. So, let’s get started.

Bash Scripting

Task 1 – Introduction

Question 1 – Are you ready to go!

Done

Task 1 - Introduction

Task 2 – Our first simple bash scripts

Question 1 – What piece of code can we insert at the start of a line to comment out our code?

 #

Question 2 – What will the following script output to the screen, echo “BishBashBosh”

BishBashBosh

Task 2 - Our first simple bash scripts

Task 3 – Variables

Question 1 – What would this code return?

Code 1

Output 1

Jammy is 21 years old

Question 2 – How would you print out the city to the screen?

echo $city

Question 3 – How would you print out the country to the screen?

echo $country

Task 3 - Variables

Task 4 – Parameters

Question 1 – How can we get the number of arguments supplied to a script?

$#

Question 2 – How can we get the filename of our current script(aka our first argument)?

$0

Question 3 – How can we get the 4th argument supplied to the script?

 $4

Question 4 – If a script asks us for input how can we direct our input into a variable called ‘test’ using “read”

read test

Question 5 – What will the output of “echo $1 $3” if the script was ran with “./script.sh hello hola aloha”

helo aloha

Task 4 - Parameters

Task 5 – Arrays

Question 1 – What would be the command to print audi to the screen using indexing.

code 2

output 2
echo "${cars[1]}"

Question 2 – If we wanted to remove tesla from the array how would we do so?

code 3

output 3
unset cars[3]

Question 3 – How could we insert a new value called toyota to replace tesla?

code 4

output 4
cars[3]='toyota'

Task 5 - Arrays

Task 6 – Conditionals

Question 1 – What is the flag to check if we have read access to a file?

-r

Question 2 – What is the flag to check to see if it’s a directory?

-d

Task 6 - Conditionals

Task 7 – Further reading

Task 7 - Further reading

Also Read: Tryhackme – Anonymous

The bash ninja

So that was it. This was an introductory room to covers the basics of the Bash scripting which will definitely come in handy in automation. Try to make some scripts that automate your enumeration and information gathering flow. On that note, i will take your leave for the next time, till then “Keep Scripting!!!”.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top