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 ?
Asked
Active
Viewed 165 times
1 Answers
0
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.

Peter
- 1
#!/bin/bash
shebang 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 itabc
orabc.sh
or whatever you like. The.sh
suffix is a convention, not a requirement. – user4556274 Sep 05 '16 at 17:05