LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 04: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, 04: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, 04:33 AM   #3
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
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, 05:18 AM   #4
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

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

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

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
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, 11:53 AM   #7
jmc1987
Member
 
Registered: Sep 2009
Location: Oklahoma
Distribution: Debian, CentOS, windows 7/10
Posts: 893

Rep: Reputation: 119Reputation: 119
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, 05:42 PM   #8
cin_
Member
 
Registered: Dec 2010
Posts: 281

Rep: Reputation: 24
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, 05: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, 07:44 AM   #10
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
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, 09:00 PM   #11
cin_
Member
 
Registered: Dec 2010
Posts: 281

Rep: Reputation: 24
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 09:03 AM. Reason: gramm'err
 
  


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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:47 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
Open Source Consulting | Domain Registration