Process

Operators and functions for working with processes and applications are described here. The Args and ArgCount functions work with any command line format. For the correct operation of other Arg... functions, the command line must have the following format.

CmdLine = [ CmdOptions ] ["-"] [ CmdParameters ]
CmdParameters = { CmdParameter }
CmdParameter = ParamWithoutSpace | "Param With Spaces" | 'Param With Spaces'
CmdOptions = {CmdOption}
CmdOption = "-" | "--" {letter} [ CmdOptionValue | CmdOptionValues ]
CmdOptionValue = "=" | ":" CmdParameter
CmdOptionValues = " " CmdParameters
-p="my value" --flag - one two three
-i:10 -n:Bob "one par" two three
--ext "*.txt" .js .html -o=/home/ak/dest /home/ak/in1 /home/ak/in2

Operators

Operator

Result

Description

$ command line

Executes the command line.

str = $ command line

Executes the command line and returns its output.

Functions

Arg(str name) str

The Arg function returns the value of the parameter with the specified name. If the parameter was not specified at the start of the script, an empty string will be returned. You can omit the initial character - in the name parameter.

Arg(str name, str def) str

The Arg function returns the value of the parameter with the specified name. If the parameter was not specified at the start of the script, def will be returned. You can omit the initial character - in the name parameter.

Arg(str name, int def) int

The Arg function returns the numeric value of the parameter with the specified name. If the parameter was not specified at the start of the script, def will be returned. You can omit the initial character - in the name parameter.

ArgCount() int

The ArgCount function returns the number of command line parameters with which the script was run.

Args() arr.str

The Args function returns a list of all command-line parameters and options with which the script has been run.

Args(str name) arr.str

The Args function returns a list of parameter values named name. You can omit the initial character - in the name parameter.

// --ext .txt .js .html -o=/home/ak/dest /home/ak/in1 /home/ak/in2
list = Args(`--ext`)
// list == [.txt, .js, .html]

ArgsTail() arr.str

The ArgsTail function returns the list of command line parameters after the options. You can explicitly specify the beginning of such parameters with -.

// --ext .txt .js .html -o=/home/ak/dest /home/ak/in1 /home/ak/in2
list = ArgsTail() // list == [/home/ak/in1, /home/ak/in2]
// -i=false - val0 -value1 "value 2"
list = ArgsTail() // list == [val0, -value1, value 2]

IsArg(str name) bool

The IsArg function returns true if the command line has an option with the specified name. Otherwise, it returns false. You can omit the initial character - in the name parameter.

Open(str path)

The Open function opens a file, directory, or URI using the OS's default application for that object type. Don't wait for the open command to complete.

OpenWith(str app, str path)

The OpenWith function opens a file, directory, or URI using the specified application. Don't wait for the open command to complete.

Run(str cmd, str params...)

Optional parameters

  • buf stdin - the buffer that will be passed to the application as standard input.

  • buf stdout - the buffer into which the standard output of the application will be written.

  • buf stderr - the buffer into which the standard error output of the application will be written.

The Run function starts the specified cmd program with parameters and waits for it to finish. Additionally, you can override the standard input and output.

buf dirout
Run("dir", stdout: dirout)
Run("bash", stdin: buf(
|`echo "dirs"
#comment
echo "%{str(dirout)}"`
))

Start(str cmd, str params...)

Optional parameters

  • buf stdin - the buffer that will be passed to the application as standard input.

The Start function starts the specified program cmd with parameters and runs the script further. Additionally, you can pass the buffer as standard input.

Start("echo", "hello, world!")
Start("bash", stdin: buf(
|`./myscript1.sh
./myscript2.sh`
))