top of page

Unmasking the Magic : The Utility of Bash

Created with Sketch.

   

    Bash is a powerful tool. No, I don’t mean to bash someone (verbally or physically.) What I am talking about is a part of the terminal ( Linux / Mac ) & on Windows ( Powershell or Command Line Processor. ) For the Windows user’s, Bash was incorporated due to the nature of its power, however you will need to do a few things to use Bash in Windows. Shell scripts can be run on various platforms and operating systems, including Unix, Linux, macOS, and even Windows through the use of emulators or virtual machines. While I won’t dive into the use of virtual machines and emulators, I will provide links to sources and video’s that demonstrate some of the possible issues explained. Let’s proceed to advance into the presence that Bash is able to be executed ( If you have Linux, Unix, or MacOS ) then it should be preinstalled.






Linux terminal, transparent view to see text & terminal for multi-use purposes.
| Transparent Terminal | 'Bourne Again Shell' |




    I will start by first explaining some the bare bone information, for anyone who is new or does not really understand Bash. Let me also inform you that I am not a professional user of Bash, and Bash is considered a programming language. I can help you understand the infinite possibilities, the tool you never knew you needed, and a stronger vision of the power this holds. Bash means: (Bourne Again Shell.) While you may not be a professional after this article, I hope to make you into a pro noob.





    While learning to code, I started to explore more about the different languages available, here is a hint, DO NOT LOOK. It is equivalent to an iceberg pyramid. Stacking down into a triangle shape, rather than up like the building. There are so many, that realistically you will never learn them all. Here is a joke, there is a programming language called: Brainf**k. The joke was actually a joke itself, meaning that is actually a programming language. Want to learn more, look no further.




                         https://www.youtube.com/watch?v=hdHjjBS4cs8





  I strongly advise you checkout the video. It is 100 seconds of Brainf**k. You may learn something, but honestly, it is hilarious. Anyways above I have a picture which shows the terminal and I have a custom color scheme set, along with transparency active. You can see the text through the terminal, to keep it over a window and type what you read. That’s pretty handy because even professionals use the internet to find commands for Bash. There is just about an infinite amount of possibilities, some are scary to think that they actually exist and work… Almost like in the movies.





8 text files that are .sh extensions (bash scripts) used to demonstrate the relveant info in the editorial.
| 8 Bash Scripts | Written in a Text-Editor |


      Above would be 8 text files that I’ve written 1 or more commands into. The extension: .sh ; is for bash scripting. While you can execute commands inside the terminal, you can also create automated scripts. These do need to be precise as each command will execute in the order of the line, then proceed to the next line under, if there is no command it will skip until there is and execute (assuming you’ve left blank spaces, and not entered random text or commands that will not execute: this could cause the script to run into an error meaning it would stop.)




     A great visual example of this is say you were the programmer for a machine. This machine was like what is in a factory, it has a conveyor belt that constantly moves at a slow and steady pace. The worker sets items on the belt and test the functionality of the code you’ve given to the machine. It works well, all of a sudden, one item seemed to cause a jam as it passed through one part of the assembly. They eventually ‘fix’ the issue and still give you a call to see if you can figure out anything. You ask the proper questions to gather information needed. You being so handy, decide to check into the 9000 lines of code you wrote in 2 days.




     You end up spending 30 hours + 3 Starbucks trips & a headache. Don’t forget the item you can throw when you’re mad and it won’t break anything. You will need that. Regardless, you finally find the issue and then realize you’re an absolute f**k*** mor**. On line 3564 you were setting the weight of the items that would be passing through on the belt to keep the speed balanced. The weight of box shape and item 3 was between 1/2 lb and no higher than 1 lb. You set the max weight at 0.99 and occasionally boxes with 1 lb would pass through, which would cause a break in the execution as you set a conditional statement that would follow each item to break if there was an error (since the belt would stop, you did not want the belt to stop due to your code while it continues to run the process. Most likely overheating and potentially causing damage.) You adjust the max weight to 1.01 lbs just to be safe, update it, and now they report back a month later no technical issues.




     That is how precise code must be, which is why it requires vigorous testing. The carnival rides you enjoy, you know how the procedure is usually to check every ride at least once before the day starts to ensure it is working, and nothing is off. That is after, the utilization has been high enough standard for someone who paid for the ride itself to use. I’d take a strong bet that the code was tested more times than that ride is ran for people, at least for a good while. Don’t worry though, that is some of the higher end visions, and here I am to teach you about Bash. I implemented the story to give you a better understanding of coding / programming and hopefully keep a topic known to be boring to many, interesting.




Sublime Text Editor | Used for writing a bash script and demonstrated in the editoral.
| Sublime Text Editor | Simple Bash Script Written |

    


     The point of scripts is generally to automate many tasks, while I previously explained a conveyor belt & a carnival ride which would consist of much more than we need to explain here today. So this might look like absolute gibberish to you, and that is okay. Honestly, the command itself isn’t what is important here. It is saved in a text editor as only that command, for memory, and it is a script which can be run by executing it. In any text editor, start the first line with #!/bin/bash . This is known as a ‘shebang’. The ‘shebang’ tells the editor “hey editor, i am a bash script, ok?” Now it will execute commands in sequence like if you were in the terminal itself.





Linux terminal executing a command for demonstration purposes.
| The Command From Sublime Text Editor | Terminal Use |

 


    I’d like to mention that I am using and demonstrating the terminal from the Linux OS. I am using the latest LTS (Long Term Support) Version - 24.04 I found this works just fine on both the Debian & Ubuntu packages supporting the 24.04 LTS version. Above is the copied command without the #!/bin/bash because that it only needed in the text editor, to configure a executable script that runs until it ends, if it does. The saved filed is ‘yourchoiceofname.sh’ similar to the 8 scripts I showed farther back in the post. I don’t plan on explaining every specific of the command above, but to simplify it is a command that is one line and has 4 seperate commands set to execute. I will explain a little more, but first let me discuss the command and what it does.





Randomly Generated Password from a bash script execution
| 64 characters, Randomly Generated from the Command |




        Above, you see a bunch of random characters, symbols, and numbers. That was a password generator. It is set to output only the password, and avoids the info you might see appear where the terminal has all kinds of lines zooming across the screen. Except here, that command would not cause that much to happen! Regardless, if you scroll back to the previous photo; you will see towards the end fold -w 64 . This is basically taking the info, -w , write the value 64, being 64 characters. It uses a combination of the info in the command that is in between these: ' ' which is like a-zA-Z  , etc. It covers the letters a-z, lowercase && the letters A-Z, all caps, + the other numbers / symbols. It randomly gathers them and outputs a completely random set of characters that can be changed just by changing the # after -w .




     The best part is it could be ran offline on most computers meaning there is not really anyway someone could see the passwords generated from their own app or software. Not all commands can be ran offline, some commands involve the internet. You can basically use any program, download any program, move to any directory, encrypt any files, and teleport around the internals of the computer system. It is really not that hard to create a script that would setup and install everything you need to perform whatever style of work you do. Most often, IT, CyberSecurity, & Developers are common roles that use the terminal with Linux or Powershell on Windows. Hackers, Ethical Hackers, & Social Engineers are common maestros using this kind of utility.



     I would like to explain more about executing commands. Let’s say that you look at the above command for the password generator, you’ll notice this: ' | ' which is called a pipe. Pipe is used to connect the output of one command to the input of another.



     You can use ‘grep’ to search through entire directories of files to find those containing a specific pattern. ‘Grep’ is a Linux command. This is useful for quickly locating relevant files. The ‘ls’ command can be used to: list directory (i.e; wherever the terminal is operating from it will display the names of all folders / file names inside the container.



     Another powerful command is cd (check directory), & this is not the same as ls. Command ‘cd’ by itself will show the directory that you’re currently in. With ls, you can see the available directories, then use cd ‘/directoryname/documents/word-documents/all/’ (just don’t use the ' ' surrounding the directory.)





using google gemini advanced AI to provide a definiton in use case relation to the article.
| Gemin Adanced AI | Pipe Command Definition

     This image should explain things clearly. It mentions the info I was slowly presenting to show you.Now, if you used, cd directoryname && ls | grep “.txt” “.pdf” “.word” “.svg” “.dox” “.png” “.jpg” and you submitted that. Here is what would happen.



     First: You would check directory and access the directory/you/named. Second: && is another symbol that does something kind of similar to how | takes the command and pushes it into the next command. && Simply means: execute the command after && ONLY IF , the command before it was successful. This does not take the previous command, and then push the info from the execution into the next command, it only runs the next command IF the previous command worked.



     Third: is | ( pushing the previous command: (ls )List Directory) into grep. Everything inside the " " is defined as a value to the grep command. They are clearly all common file, document, and image file extensions. Every value within the " " will be scanned by grep ( which scans a files inside text/code & filename or folder, looking for those defined values, and then prints the final output back to you. )




     Since we pushed the ls (list directory) command with | (pipe) into grep “filenames/words/extensions,etc” what happens is all the content inside the directory is listed, and grep does not need a specific file to scan, it scans the entire directory. Instead of doing grep “all” “my “values” filename.txt dox.pdf myjournal.word and continuing with every file inside the directory/folder… You list the directory and push the execution into a file scanner, saving you massive amounts of time.

| Customized Kali Linux Terminal | Multicolored |
| Super Cool Customized Terminal | Kali Linux |









        You can download customized packages or create one yourself, and style out your terminal. There are tons of videos on Youtube that explain how to do this. On windows you can customize the Powershell or Command Line Proccessor as well. This might not be necessary, but look, <— when you feel style, you vibe, you feel?


    


    Basically, by customizing your terminal expect to become a professional hacker, have your direct messages flooded, & be the coolest kid on the block. Okay, just make sure to wear your cap while you say this, because that was a joke. The first sentence.




    You can still be the coolest kid on the block, even if you’re older. IT IS THE BOURNE AGAIN SHELL. Thank you for attending my post, and I hope you enjoyed the read or gained some valuable insight. Sources and Misc will go below. ~ Chasen.




a sourced image used in my blog to demonstrate tech and the terminal. @copyrights to original author / designer.
| Intro Picture | Credits to Author / Designer |

Sources : # Sources








Linux Directories Explained in 100 Seconds | WATCH THIS IF: cd. ls commands confused you.



and, how to become, a totally legit. bash scripting, genius millionare. below.




Comments


bottom of page