Documentation
¶
Overview ¶
Package xargs implements the xargs builtin command.
xargs — build and execute commands from standard input
Usage: xargs [OPTION]... [COMMAND [INITIAL-ARGS]...]
Reads items from standard input (or from FILE with -a), separated by whitespace (or by NUL with -0, or by a custom delimiter with -d) and executes COMMAND (default: echo) with the items appended as arguments.
Items may be batched into one invocation per N items (-n), per N input lines (-L), or up to a maximum command-line length (-s).
Accepted flags:
-0, --null
Items are separated by a NUL character. Quoting and backslash
escapes are not handled — every character is literal.
-a, --arg-file=FILE
Read items from FILE instead of standard input. Subject to the
AllowedPaths sandbox.
-d, --delimiter=DELIM
Use DELIM as the single-byte item separator. Recognised escape
forms: \n, \t, \r, \\, \0.
-E EOF-STR
Treat an unquoted, unescaped occurrence of EOF-STR as a logical
end-of-input. Has no effect if -0 or -d is in use.
-I REPLSTR
Insert input as the value of REPLSTR in each COMMAND argument.
Implies "one input item per command" and "-L 1" semantics, and
switches tokenisation to newline-only (matches GNU xargs).
-L NUMBER
Use up to NUMBER non-empty input lines per command invocation.
-n, --max-args=N
Use at most N arguments per command invocation.
-r, --no-run-if-empty
Do not execute COMMAND if the input contains no items.
-s, --max-chars=N
Limit a single command line to N characters.
-t, --verbose
Print the resolved command line on stderr before each invocation.
-x, --exit
With -n or -L, abort if -s is too small to fit a single batch.
--help
Print usage to stdout and exit 0.
Exit codes (POSIX):
0 success
1 syntax / usage error or sub-command not allowed; also returned
when the context is cancelled mid-run.
123 any sub-command exited 1..125
124 any sub-command exited 255 (xargs stops immediately)
125 sub-command failed to start
Sandbox notes:
xargs only invokes other registered builtins through CallContext.RunCommand and respects CallContext.CommandAllowed. There is no path to host binaries; the GTFOBins shell-escape technique "xargs -a /dev/null /bin/sh" is rejected because /bin/sh is not a registered builtin. The -a FILE source goes through CallContext.OpenFile so AllowedPaths still applies.
Memory safety:
A per-token cap (MaxTokenBytes, 1 MiB) bounds any single argument and prevents unbounded buffering on infinite streams. Read chunks are 64 KiB. ctx.Err() is checked between chunks, periodically inside per-byte loops, and before each sub-command call so cancellation propagates promptly even when the input stream is infinite (e.g. /dev/zero).
Index ¶
Constants ¶
const ( // MaxTokenBytes is the largest single input item we will buffer. // A single argument longer than this is treated as an error. MaxTokenBytes = 1 << 20 // 1 MiB // DefaultMaxChars is the default command-line size when -s is unset. // Smaller than POSIX ARG_MAX (128 KiB on most Linux systems) — defensive. DefaultMaxChars = 128 * 1024 // HardMaxChars is the upper clamp applied to user-provided -s values. HardMaxChars = 1 << 20 // 1 MiB // HardMaxArgs is the upper clamp on -n / -L values. HardMaxArgs = 1 << 20 )
Resource caps. These keep the builtin defensive against malicious or runaway input regardless of the user-supplied -n / -L / -s values.
Variables ¶
var Cmd = builtins.Command{
Name: "xargs",
Description: "build and execute commands from standard input",
MakeFlags: registerFlags,
}
Cmd is the xargs builtin command descriptor.
Functions ¶
This section is empty.
Types ¶
This section is empty.