top of page
book of spells.webp

Start your journey towards mastering the CLI with our FREE Command Line Book of Spells.

By entering your email address you agree to receive emails from Command Line Wizardry. We'll respect your privacy and you can unsubscribe at any time.

  • Writer's pictureCybersecurity Ops with bash

Cybersecurity Ops with bash - Chapter 2 Solutions

Below are selected solutions for the Chapter 2 workshop questions from Cybersecurity Ops with bash.

Question 2

Modify the script to use a function. Put the if/then/else logic inside the function and then call it from the script. Don’t have the function itself produce any output. Make the output come from the main part of the script.


Note that this is just one of many possible solutions:


Question 3

Set the permissions on the script to be executable (see man chmod) so that you can run the script without using bash as the first word on the command line. How do you now invoke the script?


The chmod command can be used to give a script execute permissions. A value of 755 will give all users the ability to execute the script.

Once the script has execute permissions is can be executed directly using ./ rather than using the bash.


Question 4

Write a script called that tells how many arguments are supplied to the script.

a. Modify your script to have it also echo each argument, one per line.

b. Modify your script further to label each argument like this:

$ bash this is a "real live" test

there are 5 arguments

arg1: this

arg2: is

arg3: a

arg4: real live

arg5: test


Note that this is just one of many possible solutions:

3,013 views5 comments


Sergio O
Sergio O
Oct 27, 2022


#Print only even-numbered arguments

echo there are $# arguments


for ARG


let i++

if [ $(( i % 2 )) -eq 0 ]


echo "arg$i: $ARG"



Apr 08, 2023
Replying to

Hi. What is happening in this piece of code?

$(( i % 2 ))


Hello World
Hello World
Jul 07, 2022

There is no answer for the question 5.

Question 5 is Print only even-numbered arguments.

bottom of page