LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 01-13-2011, 05:12 AM   #1
LinuxMania_TJ
LQ Newbie
 
Registered: Dec 2010
Posts: 2

Rep: Reputation: 0
Smile Creating your own command in Linux


How can i create my own command in linux??
 
Old 01-13-2011, 05:20 AM   #2
Oliv'
Senior Member
 
Registered: Jan 2004
Location: Montpellier (France)
Distribution: Gentoo
Posts: 1,014

Rep: Reputation: 36
Hello,

You just have to code a program (bash, python, C, C++...) which does what you want

Regards,

Oliv'
 
Old 01-13-2011, 05:33 AM   #3
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,613
Blog Entries: 1

Rep: Reputation: 1047Reputation: 1047Reputation: 1047Reputation: 1047Reputation: 1047Reputation: 1047Reputation: 1047Reputation: 1047
Hi and welcome to LQ.

The easiest way would be to use BASH.
1. Save your script somewhere in your path (the best place would probably be in ~/bin);
2. Make sure that directory is in your path.
3. make it executable (chmod +x myscript)
4. You are ready to go

Is there any specific command you'd like to create?

If you go the BASH way, this should be useful:
http://tldp.org/LDP/abs/html/
 
1 members found this post helpful.
Old 01-13-2011, 06:18 AM   #4
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,634
Blog Entries: 29

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
or http://tldp.org/HOWTO/html_single/Im...inux-2.6-i386/
 
Old 01-14-2011, 10:21 AM   #5
resetreset
Senior Member
 
Registered: Mar 2008
Location: India
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,320

Rep: Reputation: 62
I don't think he meant a SYSTEM CALL, Anisha
 
Old 01-14-2011, 10:26 AM   #6
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,634
Blog Entries: 29

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
Many times newbies don't know what exactly they want, so it is better to enlighten them with other available options too!
 
Old 01-14-2011, 12:53 PM   #7
jmc1987
Member
 
Registered: Sep 2009
Location: Oklahoma
Distribution: Debian, CentOS, windows 7
Posts: 866

Rep: Reputation: 110Reputation: 110
when you say create you own command you need to be a little more clear. You can edit your bash files and create alias for commands or you can write a program and use that command. If you want to make a program then you need to learn some type of coding such as c, c++, python, perl, and many many more.
 
Old 01-14-2011, 06:42 PM   #8
cin_
Member
 
Registered: Dec 2010
Posts: 266

Rep: Reputation: 23
PATH=$PATH:/dir/to/scripts

Create the script.
Save copies of your scripts to a directory of your choosing.
You can then add the directory of the scripts to your Path...
Code:
# PATH=$PATH:/dir/to/scripts
# export PATH
...then you simply call them using their filename.
 
Old 01-15-2011, 06:17 AM   #9
LinuxMania_TJ
LQ Newbie
 
Registered: Dec 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks a lot guys!
 
Old 01-15-2011, 08:44 AM   #10
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 11,469
Blog Entries: 4

Rep: Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525
Hi,

Welcome to LQ!

Quote:
Originally Posted by LinuxMania_TJ View Post
How can i create my own command in linux??
As you can see from the responses you have been given. Your lack of being specific got varied input. I suggest that you look at 'How to Ask Questions the Smart Way' so in the future your queries provide information that will aid us in diagnosis of the problem or query. That way you will receive targeted responses.



Just a few links to aid you to gaining some understanding. I would start at 4,5 &6 since your query requirements are aligned to these. While the other links will enhance your Gnu/Linux experience;



1 Linux Documentation Project
2 Rute Tutorial & Exposition
3 Linux Command Guide
4 Bash Beginners Guide
5 Bash Reference Manual
6 Advanced Bash-Scripting Guide
7 Linux Newbie Admin Guide
8 LinuxSelfHelp
9 Getting Started with Linux

The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!
 
Old 01-16-2011, 10:00 PM   #11
cin_
Member
 
Registered: Dec 2010
Posts: 266

Rep: Reputation: 23
advent command

Once you have a directory for your homegrown commands you can try this...

I wrote a command that takes the project I am working on and makes it a callable command.
I usually work in a different directory than the one I have appended to PATH so it has proved much easier to simply call this command instead of typing the entire path to my script directory. I like to keep the languages separate, and I bounce around a bit so I just added a second argument defining the type of script it is.

Code:
# ungaunga
bash: ungaunga: command not found
# advcomm ungaunga b
# ungaunga
mah monkey
#
/src
Code:
#!/bin/bash
case "$2" in
	"b") chmod +x $1 && cp $1 /dir/to/scripts/bash/;;
	"c") cp $1 /dir/to/scripts/c/;;
	"p") cp $1 /dir/to/scripts/perl/;;
	"py") chmod +x $1 && cp $1 /dir/to/scripts/python/;;
	"r") cp $1 /dir/to/scripts/ruby/;;
	"l") cp $1 /dir/to/scripts/lua/;;
	
	*) echo -e "\nusage: `basename $0` sets command as callable\n: b bash : c C : p perl : py python : r ruby : l lua : \n";;

Last edited by cin_; 07-23-2011 at 10:03 AM. Reason: gramm'err
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Creating a Linux Terminal Command From Scratch realpockets Linux - General 9 01-18-2011 11:15 AM
[SOLVED] creating a list of word using tr command arvindk.monu Programming 5 07-13-2010 01:02 AM
Creating Command Alias? carlosinfl Linux - General 3 07-14-2007 06:32 PM
Creating on the command logs for users aliwerd Linux - General 3 06-25-2003 08:43 AM


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

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration