Skip to content

toPosixCommandLine

Converts an array of command-line arguments into a single command-line string quoted for a POSIX shell (sh, bash, zsh, …).

Each argument is wrapped in single quotes unless it consists solely of characters that are safe unquoted, mirroring Python’s shlex.quote. A literal single quote inside an argument is emitted as the '\'' idiom (close the quoted span, add an escaped literal quote, reopen), so the shell reproduces the argument verbatim — no variable expansion ($), command substitution (`), globbing (*, ?, [), or word splitting.

Use this on platforms where the command is executed through sh -c. On Windows, use toCommandLine plus cmdEscapeCommandLine instead — the two conventions are not interchangeable.

Import:

import { toPosixCommandLine } from 'obsidian-dev-utils/script-utils/cli-utils';

Signature:

function toPosixCommandLine(args: string[]): string

Parameters:

ParameterTypeDescription
argsstring[]The array of command-line arguments to convert.

Returns: string — A string representing the command-line invocation for a POSIX shell.