LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-11-2010, 09:18 AM   #1
rajesh1978
LQ Newbie
 
Registered: Jun 2010
Posts: 26

Rep: Reputation: 0
Arrow 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
 
Old 07-11-2010, 09:45 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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.
 
Old 07-11-2010, 09:57 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
You can write a script in BASH, Python, and many other languages.

You can create an alias based on existing commands.
 
Old 07-11-2010, 10:17 AM   #4
pr_deltoid
Member
 
Registered: Jun 2010
Distribution: Fedora
Posts: 289

Rep: Reputation: 41
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.
 
Old 07-11-2010, 10:52 AM   #5
rajesh1978
LQ Newbie
 
Registered: Jun 2010
Posts: 26

Original Poster
Rep: Reputation: 0
I want to use c or c++ language for that.
 
Old 07-11-2010, 10:56 AM   #6
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by rajesh1978 View Post
I want to use c or c++ language for that.
So, do you know how to compile and link ?
 
Old 07-11-2010, 11:03 AM   #7
rajesh1978
LQ Newbie
 
Registered: Jun 2010
Posts: 26

Original Poster
Rep: Reputation: 0
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
 
Old 07-11-2010, 11:23 AM   #8
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by rajesh1978 View Post
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 ?

Last edited by Sergei Steshenko; 07-11-2010 at 11:26 AM.
 
Old 07-11-2010, 11:24 AM   #9
steve296
LQ Newbie
 
Registered: Jun 2010
Posts: 9

Rep: Reputation: 1
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.
 
Old 07-11-2010, 11:26 AM   #10
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by steve296 View Post
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 ?
 
Old 07-11-2010, 11:29 AM   #11
steve296
LQ Newbie
 
Registered: Jun 2010
Posts: 9

Rep: Reputation: 1
Quote:
Originally Posted by Sergei Steshenko View Post
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.

Last edited by steve296; 07-11-2010 at 11:29 AM. Reason: typo
 
Old 07-11-2010, 11:31 AM   #12
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by steve296 View Post
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 ?
 
Old 07-11-2010, 11:35 AM   #13
rajesh1978
LQ Newbie
 
Registered: Jun 2010
Posts: 26

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Sergei Steshenko View Post
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
 
Old 07-11-2010, 11:38 AM   #14
steve296
LQ Newbie
 
Registered: Jun 2010
Posts: 9

Rep: Reputation: 1
Quote:
Originally Posted by Sergei Steshenko View Post
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.
 
Old 07-11-2010, 11:40 AM   #15
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by rajesh1978 View Post
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
.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Implementing Karmic changes ben44b Linux - Hardware 0 01-18-2010 05:22 PM
Implementing cd command ko589 Programming 4 03-02-2009 10:17 PM
Implementing IPv6 ??? ajeetraina Linux - Server 0 07-09-2007 10:40 PM
implementing ping? pcdude Programming 4 11-03-2004 03:57 AM
"Doubt in Implementing top command " manikantha Programming 1 09-24-2004 07:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration