Bash Scripting | TryHackMe
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”
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?
c)How would you print out the country to the screen?
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
c) How can we get the 4th argument supplied to the script?
d) If a script asks us for input how can we direct our input into a variable called ‘test’ using “read”
e) What will the output of “echo $1 $3” if the script was ran with “./script.sh hello hola 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.
b) If we wanted to remove tesla from the array how would we do so?
c) How could we insert a new value called toyota to replace tesla?cars=’toyota’
Task 6: Conditionals
What is the flag to check if we have read access to a file?
What is the flag to check to see if it’s a directory?
Task 7: some useful websites