• Cybersecurity 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 osdetect.sh 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 osdetect.sh 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 argcnt.sh 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 argcnt.sh 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:

752 views0 comments