Creating a Linux Terminal Command From Scratch
I am new to the Linux OS and I am very intrigued in learning all aspects of it. Currently I am using the Fedora 13 distro.
I am looking into creating my own terminal command from scratch. I researched online for some information on this subject was only able to view stuff related to OS X. I understand that they are both Unix based, are they both similar in creating these commands?
Basically all I would like is for someone to point me towards the right direction to start or complete this task.
Thanks for your help and support,
Hi and welcome to LQ.
You should start your script with:
followed by other commands. You'll find the following tutorial very useful:
Thanks for the quick reply *sycamorex.
Quick question, are linux commands such as 'mkdir', 'sed', 'rm', 'chown' ... normally first written as bash scripts and then added to the command directory so I can call them via terminal?
Ultimately I would like to create a command and not a script.
*** this is what i mean ***
No, 'mkdir', etc. are not scripts. They are binary files written in C so that's what you could
start off with.
you might want to do some reading ?
you sound just a bit confused about things
start with DangerMouses site - for fedora
The basics for ALL Linux OS's
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...
Once you have a directories 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.
Just a better understanding Mac OS derived some some Unix code but Linux did not derive from Unix. Linus Torvolds designed the kernel from scratch to resemble minux. So that makes it a unix clone.
But just another option. You can make alias's to linux commands. For example if you wanted
makedir to do mkdir you just add a alias in your bash configurations directories either in your home directory or your system wide directory.
Just read "advanced linux programming" it's offered as a free pdf file or you can buy the book.
The question you are asking is too complicated to be asking on a 'linux general' forum.
Once you have programmed a little and need help with very specific programming question, go to the programming forum.
However, chances are, all you need is to execute a few existing commands in sequence. All you need for this is a bash script.
BTW, programming takes a lot of knowledge and understanding. I would also recommend learning at least C++ as this is a standard and generic place to start.
A program is a set of instructions.
A script is a program written is a scripting language (a scripting language is where there's a separate program that interprets the script every time you use it, for example Bash or Python).
A binary is a program written in a compiled language (such as C or C++) that's then been compiled. The binary runs directly on your CPU with no intermediate program.
A command is a program that's in a directory mentioned in your PATH environment variable, so that it's executed when you just type its name in a terminal.
for posterities sake
As MTK358 explained :
Commands are globally callable programs due to their location being in the directories of your PATH.
How do they get there?
GNU creates essential programs like bash and their coreutils package.
Then each distro chooses carefully the programs that they believe are useful and want in their distro.
In this way your access to programs begins with the distro developers decisions.
Next, since GUIs are considered a standard at this point, the Desktop Environment, or the Window Manager, when loaded will carry with it software it feels is important.
Next, when you want some functionality and you find someone who has a project that fulfills this functionality and you retrieve the program, and either by your package manager or your own compilation makes it a callable command by placing the right files in the right directories.
Finally, when you want some functionality and your research for a solution returns null, then you write your own program and add it to your PATH.
Binaries are files that require you to reverse compile or find the source of to be able to read and understand its functionality. I'd suggest looking into C.
You can get the source to some of the most powerful and ubiquitous programs here... http://www.gnu.org/software/software.html
Scripts are programs written in scripting languages without compilation and so can be executed and have their source examined from the executable.
You make certain sacrifices with efficiency functionality and resource usage when working with scripting languages, but like lumak explained they are fine for executing simple command sequences, especially when those commands require modification often. I also like to prototype in a scripting language. I find it makes my C binaries come together more seamlessly.
This sounds vast and intimidating, but it really is simple.
My example of the simplicity of this process from before, shown in its entirety...
GNU Manuals... http://www.gnu.org/manual/manual.html
GNU Source Collections... http://www.gnu.org/software/software.html NOTE: bash, coreutils
|All times are GMT -5. The time now is 08:59 PM.|