Scripting / Scripts
[Not to be confused with scriptures.]
The script file itself is not what executes. The interpreter is a binary that executes on the computer and reads in the text of your script, compiles it, and then runs it on your behalf.
For example, put the following into a
helloloop text file and run it with
while true; do echo hello world sleep 1 done
⚠️ Do not forget the
Run it with
bash helloloop and you will see something like the following:
hello world hello world hello world hello world
Let it run and open another terminal.
Let’s see what it looks like in the process table.
ps -eF | grep hello
rob 9745 8473 0 3289 3476 0 19:31 pts/7 00:00:00 bash helloloop
bash is the thing running not
💡 Try to find
bash helloloopusing the
treeutility to see it’s parents.
helloloop now to cancel it.
Scripts are Horribly Inefficient
Because every script must be compiled every single time it is run (even though bytecode does help sometimes) it takes a very long time — relatively — to even start your script. A lot of people don’t care about this, but you should. This is why you should never execute a script from another script or program unless you absolutely must. This is a common source of slowing down systems in general.
💎 If you have a script that you use a lot consider rewriting it in a compiled language like Go or Rust or C.
💬 This is actually the main reason that Python is not the great language so many people think it is and you should only use it if you must.
To give you a sense here are the benchmarks on the two: