I don't exactly know the difference between a script and a few pages mention that there is almost no difference between them but I do wonder why to execute a command all we need to do is type its name and press enter but to execute a script a .sh follwos the name of the file .(If a command is also an executable file why isn't there any need for extensions in case of a command ? ) I think it is possible to create your own commands in shell as I work on a system and the names of few commands seem customized(they match the names of some people). If it is possible to create your own command then how can I view the code for a user made command ? And how can I make my own command ?
You have to make a difference between programs that are compiled to machine code from a compiled language like C and interpreted language like bash. A compiled program consists of machine code that the computer can run with no further help.
With a script, you need to tell the computer, which interpreter it should use. For example, you can run a bash script by putting the line
#!/bin/bash first in the file. It tells the computer, that it should use the bash-shell as the interpreter. If you turn on the executable bit in the file permissions, you can run it from the command line like any other program. You can leave the .sh extension away.
So by putting #/bin/bash in the first line of a script like "abc.sh" will turn it into a command and just by writing abc and pressing enter we can get the required getting executed ? Sep 5, 2016 at 16:27
#!/bin/bashshebang is the first line of the file; it has the appropriate executable bit set; and it is in your path, then you can execute that script just by typing its name. You may call it
abc.shor whatever you like. The
.shsuffix is a convention, not a requirement. Sep 5, 2016 at 17:05
@user4556274 : Thank you . And so I can find the code for that command in my directory . Sep 5, 2016 at 17:51