ASPL Programming ver 1.00
© 2024 Bassem W. Jamaleddine


12-1

   ASPL Scripts by Examples

The ASPL interpreter provides a scripting language and it can parse, analyze, and execute ASPL scripts. However, how to get the shell to load the interpeter so that the later can execute the content of the script.

The env command is used on many systems to startup a computer script. The script name, an exceutable file also called program, follows the env command and the system initializes the system environment and exec the corresponding script.

The scripting language of an interpreter typically provides a mechanism to load a script through the environment of the UNIX system. This is typically done in two ways: either by invoking the interpreter following #! and these two characters happen to be the absolute first two characters in the content of the script name, or by invoking the env directly: that is by including env on the first line and by following it by the interpreter name.

In either case the script is loaded through the UNIX shell environment. The first case requires specifying the full path to the location of the interpreter, and may not work on some UNIX systems where the loading of the special (hashclamation) shebang #! has been disabled. The second case may seem simple, yet we need to give it special attention considering the many UNIX systems and the fact that env loading mechanism has not been addressed by POSIX (different vendors implement the env following their needs). Furthermore some vendors provide the -S option supposedly to be followed by a string to be split into the script name and its argument, but fail the split and present the whole string as it is: one long string that is assumed to be the interpreter name (hence failing once again if the string contain arguments). In addition, the location of the env command may vary between systems: the env program may be located in /usr/bin, or /bin, or somewhere else.

Since all UNIX vendors (at least) load what follows the env as a single string pointing to the interpreter named program, then it is possible to generalize a solution to the loading of the interpreter and its arguments.

To overcome the env loading issues and to make ASPL portable on different UNIX systems, ASPL uses a two-lines shebangs line: the first line is to read the interpreter name, and the second line is to pass the arguments of the program. Note that the script name is the program name itself and is implicitly passed by env as $0 shell variable.

This chapter shows some scripting examples that can be run by the ASPL interpreter. All scripts can be found in the shared folder where you have installed the ASPL interpreter.

● Script dircompare.aspl

This is script is used to show how to ..

Script dircompare.aspl see SECTION 12.2.1 [Script dircompare.aspl]

 

● Script pathcompare.pl

This is script is used to show how to ..

Script pathcompare.pl WARN: IN ASPL-Scripts-by-Examples.raw THE FOLLOWING Ref: CANNOT BE RESOLVED
   <Ref:-see section -chaptit "Script pathcompare.pl" -ptt "Script pathcompare.pl" />

 

■ Executing ASPL from other programming languages

Since it is possible to pipe STDIN to the ASPL interpreter, it is possible use ASPL with other programming languages. ASPL reads the STDIN first line and determines if it is a shebang giving priority to its arguments (overriding any argument should it be specified prior to the -STDIN pipe). The following scripts show to call ASPL from Perl script. We will consider three examples:
script name        description
---------------    --------------------------------------
pathcompare.pl     compares your PATH on different hosts, 
envcompare.pl      compares your ENV on different hosts,
jarcompare.pl      compares the similarities between multiple JAR archives.


 

● Script pathcompare.pl

The Perl script pathcompare.pl shown in Listing LLLLL compares your PATH on different hosts in a cloud environment.

 

● Script envcompare.pl

The Perl script envcompare.pl shown in Listing LLLLL compares your ENV on different hosts in a cloud environment.

 

● Script jarcompare.pl

The Perl script jarcompare.pl shown in Listing LLLLL display the similarities between multiple JAR archives.