What is Linux scripting?

Linux scripting or bash (bourne again shell) scripting is the technique of taking one or more commands in the Linux command line and placing them into a single text file to be executed. This technique can be used to automate command line functions and can also be used to run multiple commands using just a single typed command on the Linux command line. Linux scripts are just a series of Linux commands.

Here’s an example: say I want to display a multiple line welcome message while I’m in the command line. There are two ways (that I know of) to do this:

1- use the echo command to display the each line one at a time

You could use two lines to display a welcome message
You could use two lines to display a welcome message

2 – write a script that will display the entire message all at once

I used the nano text editor to write the script
I used the nano text editor to write the script .The “#!/bin/bash is called a shebang. It is used to tell Linux what “interpreter” to use when going through the lines written in the script. In this case I’m using the built in bash scripting language so I have to tell Linux via the shebang that I’m using the bash scripting language otherwise the OS will not understand what I’m writing.

After I finished writing the script in order to use it I have to make it an executable program. I do this using the chmod command.

making the script executable
First is the command invocation”chmod” then “u” which stands for user the “+x” means that I’m giving executable permissions to the user. Then the last part is the file I’m changing permissions on which is “welcome”

After I set the permissions I run the script.

running the welcome script
Instead of having to type two lines to display a welcome message I just had to type a single word and the script did everything else for me.

This is just a small taste of what scripting in Linux can do. Scripting can do mundane things like display text and also advanced OS commands like process management. Thanks for reading!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s