DEV Community

Cover image for Thrash with BASH
ODOT!
ODOT!

Posted on • Updated on

Thrash with BASH

Greetings all,

If you read my last post you would understand the focus behind cybesec right now. Writing notes this AM, looking at the glitching phone screen, it's time to make things happen in a major way. Booted up Youtube via the Raspberry Pi 4 and began looking for project ideas. Before doing so, I sat and thought for a moment. Let's work on BASH deeply! Grabbing my coffee mug I start to search for how to automate the daily tasks. This is simply what the scripting language made for. First things first, let's begin with the basics. What is BASH?

BASH (BOURNE AGAIN SHELL) scripting saves the user time so certain commands aren't written repeatedly. Bourne shell (sh) is used as the format for bash files but not required at end. The script is a series of commands that make of the file. When executed, they are read line by line so it's easy syntax to write and read in my opinion.

To start a script, you first would need a shebang. This combo consist of bash # **and **bang ! followed by the path of the bash shell. There's much more behind the shebang, but that will be added in the resources below.

shebang example:

`#! /bin/bash

To find the path of the bash shell, use the following command:

which bash

output for kali is :

/usr/bin/bash

so the ending of result would be the following when using a shebang in Kali linux:

`#! /usr/bin/bash

*Nano * is an incredible text editor that is built-in most linux distributions. The Nano text editor allows users to create BASH scripts.

Installation of Nano
sudo apt install nano

Open Nano
nano
nano <filename> (this option creates the name of script)

Example:
nano myscript.sh

Navigation of the GUI is quite simple. The commands I use the most thus far are Save, Copy, Paste and Exit. There are many more commands that are great to use, but like I tell all please do your research. Don't just read my blog, but check out the resources I add below. Respectfully.

Save File

Ctrl + s

Exit Nano

Ctrl + x

Copy

Ctrl + Shift + C

Paste

Ctrl + Shift + P

Now that you have the basic commands, let's create a simple bash script that will say "LINUX IS POWERFUL!" using Nano. No worries, I will walk you through it so you don't have to sweat. Are you set. Let's get to it.

Steps:

nano myscript.sh

#! /usr/bin/bash

echo 'Linux is Powerful!

Ctrl + s * add file name "myscript.sh"

Ctrl + x

Congrats! You have completed your first BASH script. Now you are asking the question of how you run the script eh!? Hmm... I guess I'll provide that for you. When executing the script you first need to make it executable. To make it executable we use the change **file permissions **of the script.

chmod +x myscript.sh

Then to to execute the script use:

bash myscript.sh

Ha! Now your good to go with the first script fully built and ran successfully! Now, do you want to make it a bit more interesting?! Let's take it up a notch and work with variables. Here's an example of a simple variable being created and used below.

name = ODOT
echo $name

Now I suggest you to try! See if you can create simple variable to add to your script. BASH has so much more to offer allowing users to automate workflows endless. As always I provide just a insight into the world then it's up to the reader to decide if they want to learn more. Resources are always provided below to help you on your journey. Well until next blog. Peace!

*Resources *

What is Nano Text Editor?

BASH for Beginners

What is a shebang?

File Permissions

OLOG Repo

Top comments (0)