i wanna create my own commands in linux shell ?what should i do for this ?

Recommended Answers

All 3 Replies

Hi,
It is best that you read the Advanced bash scripting guide available at http://tldp.org/LDP/abs/html/
If all you want to do now is create your own command which simply calls another existing linux command, check out "alias"

commented: Question is a basic one, far from adv-scripting + the page you gave is just too big for this author to look up. +0

You can also create another directory and add it to your $PATH.

sk@sk:~$ mkdir bin
sk@sk:~$ cd bin
sk@sk:~/bin$ cat >> mycommand << _EOF_
> #!/bin/bash
> echo "hello, world"
> _EOF_
sk@sk:~/bin$ chmod +x mycommand
sk@sk:~/bin$ pwd
/home/wheel/sk/bin
sk@sk:~/bin$ export PATH=${PATH}:/home/wheel/sk/bin
sk@sk:~/bin$ cd ..
sk@sk:~$ mycommand
hello, world

There is nothing like "my command". In other words any executable is as good as a command to Linux.
Anything whose x flag is set can be executed as a command on command line by giving full path. It's ur responsibility to ensure the file actually an executable (e.g. shell, perl, py,... script or c/c++ executable...). $ /home/dir/myScript.pl If you do not specify full path to teh command linux looks up all dirs in PATH variable. So if you add "/home/dir" to PATH, you don't have to specify full path on cmd line

$ echo $PATH
.:/home/dir:/bin
$ myScript.pl

See shell variables section in man page of your shell.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.