Create and run your own command in linux

Hello Everyone !!

***Hope All are doing well ***

Today In this post we will create our own command and run its our terminal 🙂

Have a Look —-

Image

For Example , I want to create commands with name of sahil,love,linux, I am creating a simple script for that….

Lets start :-

[root@sahil ~]# owncommand.sh

#!/bin/bash

sahil()

{

echo “Hello This is my first own command “.

}

love()

{

cat /etc/issue

}

linux()

{

date

}

wq!

Save and Quit

 

 

Make it as Executive file :-

[root@sahil ~]# chmod +x owncommand.sh

 

Check permission :-

[root@sahil ~]# ll owncommand.sh

-rwxr-xr-x 1 root root 116 Jul 11 15:21 owncommand.sh

 

If I tried to run command like sahil then It will give me error as command not found:- Lets try

[root@sahil ~]# sahil

bash: sahil: command not found

 

So we need to run a command to rectify this problem :-

 

[root@sahil ~]# . owncommand.sh <—— To Installed Command in Shell Memory

 

Lets try again :-

[root@sahil ~]# sahil <———– 1st command

Hello This is my first own command .

 

 

[root@sahil ~]# love <———– 2nd command

CentOS Linux release 6.4 (Sahil) <——- updated /etc/issue file 🙂

 

 

[root@sahil ~]# linux <———– 3rd command

Thu Jul 11 15:32:44 IST 2013

 

 

 

@Aha All are commands are working file 🙂

Hope you Enjoyed and like this 🙂

Thank You!!

Happy Linux-Ing 🙂

Shahil(Shakil)

🙂 🙂 🙂

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top