Object oriented shell script


The world of programming is so interesting that you can always see something original. Have you ever thought about putting your variables and functions in one class when writing shell scripts? Don’t think it’s impossible. No, I saw another object-oriented thing on the Internet. Shell doesn’t support it. You need to make something by yourself. It’s really a hacker who can figure out everything.

Of course, it’s not really object-oriented, because it’s just encapsulation, and it doesn’t support inheritance and polymorphism. The perverse thing is that he supports typeID, shit!

Let’s see how he did it. The following script may be a bit confusing. I wanted to explain. Later on, I think it’s better for you to study it on your own. In fact, it’s not difficult to understand it. Let’s give you a few points.

We can see that the following script defines functions such as class, func, VaR and new, which are actually so-called keywords.
Class is a function that records the class name.
Func and VaR actually record member function names and member variables as variables with the same prefixes.
The new method mainly records instances. Let’s focus on the for loop in the new function. The core is there.
The script is as follows:
Object oriented shell script

Next, let’s look at the routines.
Object oriented shell script