Below i’ll try to give an idea about how bash commands are implemented in linux by illustrating a small example.
Simple way to create a command( in C ) ‘hello’ which prints hello world.
- Step1 : Create a cprogram “test.c” to print the string “hello world” by first opening the file “test.c” using the text editor “vim”
and then writing into it
- Step 2 : now compile the program by using the compiler gcc
to produce an executable file” a.out”.Now this file is the object file which prints the string “hello world” to the monitor.for executing the file we use as
- Step 3 : Actually, a command like “cp” has it’s executable file in the directory /bin ,so by copying our executable file to that folder we can use it as a command .
sudo cp a.out /bin/hello
which prompts for the root password
Now we can use the command “hello” in the bash prompt to print “hello world” on the screen.