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.
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.
$who = "world";
echo "hello $who\n";
bob@pros> psh files/hello.psh
hello world
Pequod decides how to read a file by a single test: does it contain a <?
tag?
<? anywhere → the whole file is pure code (like the
example above). This is the natural mode for shell scripts.<? → the file is a template: text outside the
tags is emitted literally, code runs inside. This is how you build web pages.You rarely think about it — write scripts as plain code, write pages as templates. The web page chapter covers template mode in full.
Variables start with $. No declaration; assign and use.
$name = "Ada";
$year = 1815;
$active = 1;
echo $name; // Ada
echo $year + 10; // 1825
Pequod has three value types:
| Type | Example | Notes |
|---|---|---|
| Integer | 42, -3 | 64-bit signed. All arithmetic is integer. |
| String | "hi", 'x' | Single or double quotes. Interpolation in both. |
| Array | [1, 2, 3] | Ordered, associative. See Reference. |
7 / 2 is
3. If you need fractional values, keep them as strings or scale to integers (e.g. cents).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!
| Group | Operators |
|---|---|
| Arithmetic | + - * / % |
| String | . (concatenate) |
| Compare | == != < > <= >= |
| Logical | && || ! (and short-circuit) |
| Assign | = += -= *= /= .= |
| Step | ++ -- |
| Ternary | cond ? a : b |
$n = 5;
$n += 3; // 8
$n++; // 9
echo $n > 10 ? "big" : "small"; // small
# hash comment (whole line)
// slash comment (whole line)
/* block comment
over several lines */
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