pwd

package
v0.0.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package pwd implements the pwd builtin command.

pwd — print the absolute pathname of the current working directory

Usage: pwd [-LP] [--help]

Print the absolute pathname of the shell's current working directory to standard output. Stdin is not used. Extra positional arguments are ignored to match GNU coreutils and bash behavior.

Flags:

-L, --logical   Use the shell's tracked logical path (default).
                The path may contain symbolic links, exactly as the
                user reached the directory. This matches the POSIX
                default and the bash builtin default.
-P, --physical  Resolve all symbolic links so the printed path contains
                no symlinks and no "." or ".." components.
-h, --help      Print usage to stdout and exit 0.

If both -L and -P are given on the same invocation, the last one wins (matches POSIX and bash, implemented via pflag's declaration-order Visit traversal).

Symlink resolution for -P is sandbox-safe: it walks the absolute path component-by-component using callCtx.LstatFile and callCtx.ReadlinkFile, never calling os.Lstat / os.Readlink directly. The total number of symlink expansions is capped at maxSymlinkHops (40) to defeat cycles, matching the Linux ELOOP limit.

Sandbox best-effort for -P: if a path component lies outside the AllowedPaths sandbox (a common case when the working directory is itself the sandbox root), the resolver cannot walk that component and gives up gracefully — falling back to the logical path. This means "pwd -P" never produces a hard error from the sandbox; it returns the best canonical path it can compute.

Exit codes:

0  Success — a working directory was written (logical or physical).
1  Error — invalid flag, or the runner exposes no working directory.

Index

Constants

This section is empty.

Variables

View Source
var Cmd = builtins.Command{
	Name:        "pwd",
	Description: "print working directory",
	MakeFlags:   makeFlags,
}

Cmd is the pwd builtin command descriptor. Help is intentionally not set: pwd registers flags, so the `help` builtin invokes `pwd --help` to produce its description, keeping `help pwd` and `pwd --help` identical.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL