Peios Learn
Documentation

Peios

Peios Peios Kernel Universal Directory Project

Developer Tools

Trail Acta Provium clackatoo CAF GCSL Pekit

Applications

Framewright

Standards and Conventions

Standards and Conventions Peios Specifications
Peios

Scripts and the System

Single-page view · as markdown

Printing Output and Reading Command Status

Peios / Using Peios / Scripts and the System

A command reports results in two ways: the data it writes to its output, and an exit status, a number where zero means success. Scripts use output for data and status for decisions. These commands are the building blocks for both. The man page for each command lists every option.

Your shell has its own versions of some of these commands, such as echo, printf, test, and kill. To run the utility itself, put peiosutils before its name, as some examples here do.

The examples use sample file names such as report.txt. Create those files first, or substitute your own.

Print messages and values #

echo prints its arguments, which suits a short fixed message:

peiosutils echo 'Build complete'

For any value that comes from elsewhere, use printf with a fixed format, so that the value can't be read as an option or as formatting:

peiosutils printf '%s: %d\n' Aster 3

Keep the format under your control and pass data as the later arguments. The format repeats if more arguments remain.

seq 2 2 8 prints numbers from 2 to 8 in steps of 2, and yes sample prints a line repeatedly until it is stopped. Don't pipe yes into a program to answer prompts you haven't read: use the program's own option for running without prompts. numfmt --to=iec-i shortens a byte count with a binary prefix, which scales by powers of 1024. The result is rounded, so keep the exact number for any calculation.

Run a command with a changed environment #

env runs one command with an extra or changed environment variable, without changing your shell:

env PEIOS_EXAMPLE=ready peiosutils printenv PEIOS_EXAMPLE

printenv prints one variable when you name it, and fails if the variable doesn't exist, which tells an empty value apart from a missing one. Without a command, env prints the whole environment, which can contain credentials, so don't share that output. A cleared environment helps make a command repeatable, but it isn't a security boundary.

Test conditions #

test reports a condition through its exit status and prints nothing:

if peiosutils test -f report.txt; then
  peiosutils printf '%s\n' 'Report is a regular file'
fi

Quote variables so that an empty value stays one argument. A file test describes one moment: the file can change before you use it. true and false exist only for their status. Don't add || true to hide a failure unless you've handled the failure you expect.

expr 7 + 5 evaluates a small integer expression; quote operators such as * that the shell would interpret. factor 84 prints the prime factors of a number.

Read exit statuses #

A false condition isn't always an error. expr, for example, uses one status for a zero or empty result, another for a true result, and a third for an invalid expression. In a pipeline, each command has its own status, and the shell decides which one the pipeline reports. Read a command's man page before treating every nonzero status the same way.

Save a stream while showing it #

tee writes its input both to standard output and to a file:

printf 'Starting\nFinished\n' | tee progress.log

tee replaces the file's contents unless you use append mode. A new file inherits security from its directory, and an existing file keeps its own, so choose the directory with care when the stream holds private data.

Commands on this page #

This page covers these commands:

CommandUse it toManual
echoPrint a short messageecho(1)
printfPrint values with a fixed formatprintf(1)
seqPrint a sequence of numbersseq(1)
yesPrint a line repeatedlyyes(1)
numfmtFormat numbers for people to readnumfmt(1)
envRun a command with a changed environmentenv(1)
printenvPrint an environment variableprintenv(1)
testCheck a conditiontest(1)
true, falseSucceed or failtrue(1), false(1)
exprEvaluate a small expressionexpr(1)
factorPrint prime factorsfactor(1)
teeCopy a stream to a file and to outputtee(1)

Reading System Information

Peios / Using Peios / Scripts and the System

Use these commands to read facts about the running system: the time, what is running, how much processing capacity is available, and the terminal you are using. Each value describes one moment, so don't rely on it staying the same. The man page for each command lists every option.

Read the time #

Print the current time in Coordinated Universal Time (UTC), in a form that other programs can read unambiguously:

date -u '+%Y-%m-%dT%H:%M:%SZ'

Printing a time doesn't change the clock. Setting the clock requires the relevant authority, and can affect scheduled jobs. To manage the clock and time zone, see Keeping the Time.

Identify the system #

uname -s prints the kernel's name and uname -o the operating system's. arch prints the machine architecture. These values don't tell you which version of each installed component you have, or whether a particular program will run: use the package information and each program's own checks for that.

hostname prints the machine's host name. Another machine can't necessarily find this one by that name; that depends on the network and its name service. Make a lasting change through the network configuration, because a configuration service can restore its own value over a name you set directly.

hostid prints a short identifier kept for compatibility. It can repeat across machines, so never use it to identify a machine securely.

Check capacity and load #

nproc prints the number of processors available to the current program, which can be fewer than the machine has. Memory and storage can limit parallel work too, so use it as a starting point when choosing how many jobs to run.

uptime shows how long the system has been running and its load: a measure of work that is running or waiting, not a percentage of processor use. For signed-in sessions, use Inspecting and Ending Sessions instead.

Check the terminal #

tty prints the terminal connected to standard input, and fails if input comes from a pipe or a file. A script can use that status to tell whether a person is typing. stty -a shows the terminal's settings, such as whether typed characters are echoed. If a script changes those settings, save them first and restore them even when the script fails.

Commands on this page #

This page covers these commands:

CommandUse it toManual
datePrint or set the timedate(1)
unamePrint system identifiersuname(1)
archPrint the machine architecturearch(1)
hostnamePrint the host namehostname(1)
hostidPrint the host identifierhostid(1)
nprocPrint the processors availablenproc(1)
uptimePrint how long the system has run, and its loaduptime(1)
ttyPrint the terminal connected to inputtty(1)
sttyRead or change terminal settingsstty(1)

Running and Controlling Commands

Peios / Using Peios / Scripts and the System

Use these commands to control how and how long another command runs. They suit short jobs in a terminal or a script. A job that must keep running, restart when it fails, or start when the machine starts belongs to the service manager instead; see Services and Jobs. The man page for each command lists every option.

Wait and set time limits #

sleep 0.1 pauses for a tenth of a second. A pause doesn't prove that anything finished, so wait for an explicit sign that a service is ready rather than sleeping and hoping.

timeout stops waiting for a command after a time limit:

timeout 1 peiosutils sleep 0.1

When the limit expires, timeout sends a signal, and the command must still respond to it. An option can force a stop after a grace period, but a command stopped part way through can leave partial output behind. See timeout(1) for its exit statuses.

Keep a command running after you disconnect #

nohup starts a command that keeps running when its terminal disconnects. Output that would have gone to the terminal goes to nohup.out in the working directory instead. A new nohup.out gets security that admits only you; an existing one is added to and keeps its own security. nohup doesn't put the command in the background (end the line with & for that), and it doesn't protect the command from failing, other signals, or shutdown.

Adjust priority and buffering #

nice -n 5 runs a command with a lower scheduling preference, so it yields to other work. Raising a command's preference needs extra authority. Niceness doesn't change the command's identity or what it can access.

When a pipeline's output arrives late because a program holds it in a buffer, stdbuf -oL asks the program to write each line as soon as it is complete. It works only for programs that use the standard C output functions; a program's own option for flushing output is more reliable.

Send signals #

peiosutils kill -l lists the signals. kill sends a signal to a process: a request to change state, which a program can handle. The usual stop signal lets a program clean up; a forced kill doesn't. Process numbers are reused after a process ends, so check the target first. Whether you can signal a process is an access decision, and knowing its number grants nothing.

Run a command in another root directory #

chroot runs a command with a different directory as its root, so that absolute paths are found inside that directory. The directory must contain everything the command needs, including its libraries. A changed root only changes where paths are looked up: it doesn't change the command's access token, privileges, network access, or open files, so it isn't a way to contain untrusted code. It also requires the relevant authority.

Flush pending writes #

sync asks the system to write pending changes to storage. How durable the data then is still depends on the filesystem and the device. sync doesn't make a half-written file complete or check that its contents are right.

Commands on this page #

This page covers these commands:

CommandUse it toManual
sleepPause for a timesleep(1)
timeoutRun a command with a time limittimeout(1)
nohupKeep a command running after a disconnectnohup(1)
niceRun a command with a different prioritynice(1)
stdbufChange a command's output bufferingstdbuf(1)
killSend a signal to a processkill(1)
chrootRun a command in another root directorychroot(1)
syncWrite pending changes to storagesync(1)

Checking Who a Command Runs As

Peios / Using Peios / Scripts and the System

whoami, id, groups, and logname give quick answers about the identity a command runs with. They show the account name and group memberships, but not everything that decides what the command can do. For that, read the command's access token with token.

Read the account name #

whoami prints the name of the account the command runs as. If the identity service can't find a name for the account, whoami fails, but the command still has an identity: a failed lookup is only a failed lookup.

logname prints the account that signed in to the session. It can differ from whoami when a program has taken on another identity.

Read identity numbers and groups #

id shows the account and its groups as numbers, with their names, and adds the user's security identifier (SID) and integrity level. The numbers are kept for compatibility. Peios decides access with SIDs and the other contents of the token, and the numbers can't show all of them: some groups have no number, and a deny-only group looks the same as an ordinary one. Two commands can print the same numbers and still be allowed different things.

groups prints the group memberships that have numbers.

Ask about the command or about an account #

Without an account name, id and groups describe the command you run them from, using its token. With an account name, they ask the identity service about the account record instead. A token includes groups added at sign-in, such as Everyone, that aren't stored in the account record, so the two answers can differ without either being wrong.

See the full token #

When an access decision depends on more than names and numbers, read the token:

token show --all

It shows every group with its attributes, the privileges, and the integrity level. See Inspecting Effective Identity.

Commands on this page #

This page covers these commands:

CommandUse it toManual
whoamiPrint the account a command runs aswhoami(1)
lognamePrint the account that signed in to the sessionlogname(1)
idPrint identity numbers, names, SID, and integrity levelid(1)
groupsPrint group membershipsgroups(1)
tokenShow the full access tokentoken(1)

Peios Learn — documentation for Peios software.

Built with Trail.