LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Creating your own command in Linux (https://www.linuxquestions.org/questions/linux-newbie-8/creating-your-own-command-in-linux-856039/)

LinuxMania_TJ 01-13-2011 04:12 AM

Creating your own command in Linux
 
How can i create my own command in linux??

Oliv' 01-13-2011 04:20 AM

Hello,

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

Regards,

Oliv'

sycamorex 01-13-2011 04:33 AM

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/

Aquarius_Girl 01-13-2011 05:18 AM

or http://tldp.org/HOWTO/html_single/Im...inux-2.6-i386/

resetreset 01-14-2011 09:21 AM

I don't think he meant a SYSTEM CALL, Anisha :)

Aquarius_Girl 01-14-2011 09:26 AM

Many times newbies don't know what exactly they want, so it is better to enlighten them with other available options too!

jmc1987 01-14-2011 11:53 AM

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.

cin_ 01-14-2011 05:42 PM

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.

LinuxMania_TJ 01-15-2011 05:17 AM

Thanks a lot guys!

onebuck 01-15-2011 07:44 AM

Hi,

Welcome to LQ!

Quote:

Originally Posted by LinuxMania_TJ (Post 4222696)
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!

cin_ 01-16-2011 09:00 PM

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";;



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