Skip to content

sh

import { sh, ShellError } from 'sysopkit/op/sh';

Executes a command string via sh -c.

const result = await sh('hostname');

Throws ShellError on non-zero exit codes outside the 64-78 range.

const text = await sh('cat /etc/hostname');
class ShellError extends ExecError {
cmd: string[];
exitCode: number;
stdout: string;
stderr: string;
toString(): string; // formatted error with all fields
}

Quote a value for safe interpolation into a shell command:

import { sh, $_ } from 'sysopkit/op/sh';
const text = await sh(`cat ${$_(filePath)}`);