What is a Bash Script?
In computer programming, a script is a program or sequence of instructions that is interpreted or carried out by another program rather than by the computer processor (as a compiled program is). — searchenterpriselinux.techtarget.com
So basically, a bash script is a file in Linux that can be used to automate a list of commands that you normally execute in a specific order. In a bash script, bash is the scripting language we are using. Bash is short for Bourne Again Shell and comes pre-installed on most Linux machines. A bash script can be written in any text editor, and usually saved with a file extension of
.sh, however the
.sh file extension is optional.
We can use a Bash script to simplify repetitive tasks. For example, to change the WiFi card’s MAC address using the “macchanger” utility (built into Kali Linux) we run the following commands:
ifconfig wlan0 down macchanger --mac 00:11:22:33:44:55 wlan0 ifconfig wlan0 up dhclient wlan0
Info: The above code is assuming that you are trying to change the MAC address of your wlan0 device, which in my case is my wireless network adapter. You can check your connections using
iwconfig in Terminal.
Now, it’s okay if you want to keep typing the above commands every time you want to change your mac address, however it can get annoying after a while. Wouldn’t it be easier if we could just run a simple script that could automatically run the commands shown above? The answer is, Yes. In the following article, I am going to teach you how to create a very basic Linux Bash script, without creating the infamous “hello world” script. 🙂