Bash Scripting | TryHackMe

br4ind3ad
2 min readJun 26, 2021

A write-up of bash scripting room.

Task 1: Introduction

recommended and a really awesome website: https://devhints.io/bash

Task 2: Our first simple bash scripts

a) What piece of code can we insert at the start of a line to comment out our code?
→ #

b) What will the following script output to the screen, echo “BishBashBosh”
→ BishBashBosh

Task 3: Variables

→There is no space in a variable name, the “=” and the value

→Use $ in front of the variable name in order to use it

→ The section between set -x and set +x will be debugged

a)What would this code return?
Jammy is 21 years old

b)How would you print out the city to the screen?
echo $city

c)How would you print out the country to the screen?
echo $country

Task 4 Parameters

a) How can we get the number of arguments supplied to a script? //research on the internet
$#

b) How can we get the filename of our current script(aka our first argument)? //research on the internet
$0

c) How can we get the 4th argument supplied to the script?
#4

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

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

→ as $1=hello, $2 =hola, $3 =aloha

→ echo $1 $3 = hello aloha

Task 5: Arrays

a) What would be the command to print audi to the screen using indexing.
echo “${cars[1]}”

b) If we wanted to remove tesla from the array how would we do so?
unset cars[3]

c) How could we insert a new value called toyota to replace tesla?cars[3]=’toyota’

Task 6: Conditionals

What is the flag to check if we have read access to a file?
“-r”

What is the flag to check to see if it’s a directory?
“-d”

Task 7: some useful websites

--

--