This is the 28th day of my participation in the August Text Challenge.More challenges in August

Aviator command line

AviatorScript also provides a command line tool to easily execute scripts directly.

Installation and Execution

  1. Install, please downloadaviatorSave the file to a certain systemPATHDirectories in a path (e.g~/bin) :
$ wget https://raw.githubusercontent.com/killme2008/aviator/master/bin/aviator --2020-04-26 21:41:04-- https://raw.githubusercontent.com/killme2008/aviator/master/bin/aviator Resolving localhost (localhost)... : : 1, 127.0.0.1 Connecting to localhost (localhost) | : : 1 | : 1081... Failed: Connection refused. Connecting to localhost (localhost) | 127.0.0.1 | : 1081... connected. Proxy request sent, awaiting response... 200 OK Length: 5289 (5.2k) [text/plain] Saving to: 'aviator'Copy the code
  1. Change to executable:
$ chmod u+x aviator
Copy the code
  1. Executing this command will automatically download and install the Aviator JAR file to~/.aviatorscriptDirectory:
$ aviator
Downloading AviatorScript now...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   153  100   153    0     0     94      0  0:00:01  0:00:01 --:--:--    94
100  505k  100  505k    0     0   199k      0  0:00:02  0:00:02 --:--:--  663k
Usage: java com.googlecode.aviator.Main [file] [args]
     : java com.googlecode.aviator.Main -e [script]
     : java com.googlecode.aviator.Main -v
Copy the code
  1. Save the following script as a filehello.av
p('Hello, AviatorScript! ');Copy the code
  1. Execute the script:
$ aviator hello.av
Hello, AviatorScript!
Copy the code
  1. You can also execute a script directly from the command line through-eOptions:
$ aviator -e "p('Hello, AviatorScript! ');" Hello, AviatorScript! nullCopy the code

The final null is the execution result of the entire expression.

Command line arguments

The ARGV array can be called in the script to ask:

p("ARGV count is: " + count(ARGV));

for arg in ARGV {
  p(arg);
}

p("ARGV[0] = "  + ARGV[0]);
Copy the code

Save as test.av and execute:

$ aviator test.av 1 2 3
ARGV count is: 3
1
2
3
ARGV[0] = 1
Copy the code

We pass in the command line argument 1, 2, 3, so count(ARGV) returns 3, iterate through the array through the for loop and print, and finally print ARGV[0], the first command line argument, separately.

Upgrade and other commands

AviatorScript can be upgraded with upgrade:

$ aviator upgrade The script at /Users/boyan/bin/aviator will be upgraded to the latest stable version. Do you want to continue [Y/n]? Y Upgrading... /Users/boyan/bin/aviator: line 123: [darwin18: command not found % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 137 100 137 0 0 99 0 0:00:01 0:00:01 --:--:-- 99 100 5289 100 5289 0 0 2700 0 0:00:01 0:00:01 --:--:-- 5165k The The self - install the jar already exists at/Users/by boyan /. Aviatorscript/self - installs/aviator - 5.0.0. Jar. If you wish to re-download, delete it and rerun "/Users/boyan/bin/aviator self-install".Copy the code

Because the current version is the latest, it will not be reinstalled.

The install file is under ~/. Aviatorscript/self-安 装.

View the version via the -v option:

$aviator -v AviatorScript 5.0.0-rc3-snapshotCopy the code

Third-party dependencies

Starting with 5.2.4, if you want to use third-party libraries for script invocation from the command line, you can place the jar package in the user home directory ~/.aviatorScript /deps. It will be automatically added to the JVM’s CLASSPATH after startup. You can also modify the directory using the AVIATOR_DEPS environment variable.