Pequod / PiROS manual ↑ Manual home
01 · Basic usage

Getting started with Pequod

Run a script from the shell, learn the value types, and understand the one rule that decides whether a file is treated as plain code or as an HTML template.

Running a script

psh is a normal PiROS command. Give it the path to a script:

bob@pros> psh files/hello.psh

Author scripts with the prano editor (prano files/hello.psh), or push them from your own machine. A script's output goes to the terminal — or, when the script is served by tintin, into the web response.

files/hello.psh
$who = "world";
echo "hello $who\n";
bob@pros> psh files/hello.psh
hello world

Two kinds of file

Pequod decides how to read a file by a single test: does it contain a <? tag?

You rarely think about it — write scripts as plain code, write pages as templates. The web page chapter covers template mode in full.

Variables

Variables start with $. No declaration; assign and use.

$name = "Ada";
$year = 1815;
$active = 1;
echo $name;          // Ada
echo $year + 10;     // 1825

Types

Pequod has three value types:

TypeExampleNotes
Integer42, -364-bit signed. All arithmetic is integer.
String"hi", 'x'Single or double quotes. Interpolation in both.
Array[1, 2, 3]Ordered, associative. See Reference.
No floats. Pequod arithmetic is integer-only — 7 / 2 is 3. If you need fractional values, keep them as strings or scale to integers (e.g. cents).

Strings & interpolation

Both quote styles interpolate $variables. Use \n, \t, \\, and escaped quotes.

$user = "mary";
echo "hi $user\n";      // hi mary
echo 'hi $user\n';      // hi mary  (single quotes interpolate too, in psh)

Concatenate with the dot operator .:

$greeting = "hi, " . $user . "!";
echo $greeting;          // hi, mary!

Operators at a glance

GroupOperators
Arithmetic+ - * / %
String. (concatenate)
Compare== != < > <= >=
Logical&& || ! (and short-circuit)
Assign= += -= *= /= .=
Step++ --
Ternarycond ? a : b
$n = 5;
$n += 3;                 // 8
$n++;                     // 9
echo $n > 10 ? "big" : "small";   // small

Comments

# hash comment (whole line)
// slash comment (whole line)
/* block comment
   over several lines */

Example: a tiny report

Putting the basics together — variables, a loop, arithmetic, and formatted output.

files/report.psh
$items  = ["cpu", "disk", "net"];
$counts = [12, 44, 7];
$total  = 0;

for ($i = 0; $i < count($items); $i++) {
    echo $items[$i] . ": " . $counts[$i] . "\n";
    $total += $counts[$i];
}
echo "total: $total\n";
bob@pros> psh files/report.psh
cpu: 12
disk: 44
net: 7
total: 63
← Manual home Command reference →