So, bash
is a shell. That basically means it is an interface that allows you to use the computer. It is an actual binary executable that runs directly on the cpu. (Written in C and compiled to native machine code)
Regarding your question about saving the file as a .sh -- linux doesn't care about the file extension. You could happily leave the extension off entirely and it would work just the same. You need two things to make a script work:
- Execute bit (+1 in hex) on the file -- you can just do chmod +x FILE to set it
- script interpreter at the first line (#!/path/to/executable)
For #2 when you execute a file the shell will take a look and if it looks like a text file AND the first line has the "shebang" which is the characters #! and then a path to an executable, it will consider that file a script and pass it to the interpreter in that path. For a bash script you want to have the path to bash here. This is pretty powerful, and how you can make perl scripts, python, php, etc all executable directly from the command line. You could even write your own program that then interprets scripts and put it here. I think you may even be able to chain other scripts here, but I'm not sure.
Bash has a pretty powerful scripting language and you can do a lot of stuff with it. In fact scripts such as these are heavily used in most linux distributions for stuff like starting/stopping services and such. Although those scripts tend to be written against
sh instead of
bash. Bash is basically a clone of sh but is more advanced and supports more stuff. If you write scripts against sh you can be more portable because bash may not be available on every computer but sh is likely to be. HOWEVER I would not worry about that bit right now and in all reality bash is going to exist pretty much everywhere anyways.
There are lots of guides and examples for bash scripting online and I will leave it up to you to find some.
So, in terms of how near to the 0's and 1's is bash, well, not very, but that doesn't matter. I would say it goes like this:
- Directly writing assembly is pretty much as low as you can go
- And then the next level up is writing code that compiles directly to native machine instructions (like c or c++)
- Then your next level up would be code that compiles into an intermediate language that is then ran in a virtual machine (like java, c#, or scala)
- Then you have interpreted scripts which are not even compiled at all but are interpreted right when they are ran (like bash scripts, php, or javascript).
If you are going for efficiency then being higher up in that list might be important, although honestly there is some pretty fast code lower down in that list nowadays. If you are just learning stuff, then don't worry, this isn't really important.
Hopefully that all helps and I'm sure others will chime in with more.