LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Implementing my own Command (https://www.linuxquestions.org/questions/programming-9/implementing-my-own-command-819215/)

rajesh1978 07-11-2010 09:18 AM

Implementing my own Command
 
Hi,
I want to have a command of my own.
Let the command name is MyDate and it shows the date and time.
what I need to do for that? What are the steps I need to follow?

When I am in the console, I want to use it same way I use the other commands like cd,ls etc

Please guide

grail 07-11-2010 09:45 AM

Quote:

what I need to do for that?
You need to pick a language to write it in.
Quote:

What are the steps I need to follow?
Get some lessons in the language you want to use.

When the question has no substance unfortunately so do the answers.

pixellany 07-11-2010 09:57 AM

You can write a script in BASH, Python, and many other languages.

You can create an alias based on existing commands.

pr_deltoid 07-11-2010 10:17 AM

It sounds like what you're talking about is using a Bash function. You can find a real quick, easy tutorial for making one. Otherwise, there are a lot of languages to do it with or aliases, as was suggested.

rajesh1978 07-11-2010 10:52 AM

I want to use c or c++ language for that.

Sergei Steshenko 07-11-2010 10:56 AM

Quote:

Originally Posted by rajesh1978 (Post 4029918)
I want to use c or c++ language for that.

So, do you know how to compile and link ?

rajesh1978 07-11-2010 11:03 AM

Yes, I can write a program or write a library which gives me the date and time.

Suppose I have the exe or lib which gives me the desired output then what I need to do to execute it on the console as command like ls,cd etc

Sergei Steshenko 07-11-2010 11:23 AM

Quote:

Originally Posted by rajesh1978 (Post 4029927)
Yes, I can write a program or write a library which gives me the date and time.

Suppose I have the exe or lib which gives me the desired output then what I need to do to execute it on the console as command like ls,cd etc

So, stating that you can write a program, how did you check the programs you'd written ?

steve296 07-11-2010 11:24 AM

As far as I know, the console commands are found in /bin and /usr/bin. It may suffice to just put the executable into /usr/bin.

Sergei Steshenko 07-11-2010 11:26 AM

Quote:

Originally Posted by steve296 (Post 4029948)
As far as I know, the console commands are found in /bin and /usr/bin. It may suffice to just put the executable into /usr/bin.


What for/why ?

steve296 07-11-2010 11:29 AM

Quote:

Originally Posted by Sergei Steshenko (Post 4029949)
What for/why ?

He said that he wants to have a command of his own, which he can use like the built-in ones like ls, or cd. I think that could be achieved by putting an executable into the same folder where the other commands reside. Feel free to call me crazy.

Sergei Steshenko 07-11-2010 11:31 AM

Quote:

Originally Posted by steve296 (Post 4029951)
He said that he wants to have a command of his own, which he can use like the built-in ones like ls, or cd. I think that could be achieved by putting an executable into the same folder where the other commands reside. Feel free to call me crazy.


Built-in into what ?

rajesh1978 07-11-2010 11:35 AM

Quote:

Originally Posted by Sergei Steshenko (Post 4029946)
So, stating that you can write a program, how did you check the programs you'd written ?

Assume that I have a .c file and that I have written in Linux and rcompiled that using gcc compiler and when I run the executable it gives me the desired output.
suppose that exe is int the /usr/Hoge/Test then I am able to run that like ./executablefile
I want that I should run that execuatable from any path and without giving command like ./executablefile

I want to give just executablefile (as ls and cd command) from any path

steve296 07-11-2010 11:38 AM

Quote:

Originally Posted by Sergei Steshenko (Post 4029953)
Built-in into what ?

Umm.. yeah, sorry for failing basic computer science rigor.

*starts to write down what he means, but decides that its stupid and cuts it out*

Let's just skip this, I mean the commands that he can use without going into the folder where the executable resides, and run it from there (or otherwise referencing the full path). Sorry, linux newbie here.

Sergei Steshenko 07-11-2010 11:40 AM

Quote:

Originally Posted by rajesh1978 (Post 4029957)
Assume that I have a .c file and that I have written in Linux and rcompiled that using gcc compiler and when I run the executable it gives me the desired output.
suppose that exe is int the /usr/Hoge/Test then I am able to run that like ./executablefile
I want that I should run that execuatable from any path and without giving command like ./executablefile

I want to give just executablefile (as ls and cd command) from any path

Perform WEB search on two things:

bash aliases

and

PATH environment variable
.


All times are GMT -5. The time now is 04:18 PM.