linux bash script example

Linux Bash Script Beginner Tutorial : Change MAC address – 2016

What is a Bash Script?

linux bash script example

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). —

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

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. 🙂

Continue reading