Quick tutorial - Shell script

This tutorial shows the very basics of how to make your own commands for Terminal, in other words shell scripts.

First we are going to create a simple nano file which is going to be the base for your script. This single file will contain all the information for your command.

 nano tellmesomething.sh  /notice that .sh is not required but it clarifies things. Also remember to consider that some of the command names may already have taken.

In this case I will make a script that shows date and configuration of the computer. Write date and ifconfig and save the file.

This is not over yet though! You can't run your command without doing some actions first.

 chmod +x  tellmesomething.sh  gives the needed rights for all the users to execute this command. 

 sudo cp tellmesomething.sh /usr/local/bin  copies your script into this location so you are able to run it.

Now you are able to run your very own script and it should look like this:

Now you know how to create a basic shell script. Here is some command you may find useful when you continue further with scripting.

 #!/bin/bash  a comment you need to put into a nano file while you are using python.
 nano .bashrc  with this command you are able to edit the script that will be executed always when the terminal is opened. For example you can add the command date to this file and every time you open the terminal the dated is showed.
 ./tellmesomething.sh  will run your script in the current location.


Popular Posts