Syntax
Description
Thepwd (print working directory) command displays the absolute path of the current working directory within Nash’s virtual filesystem. It outputs a single line containing the full path from the root / to your current location.
pwd always returns paths within Nash’s Virtual Filesystem (VFS), not the host system’s filesystem.Arguments
Thepwd command takes no arguments or flags.
Behavior
- Reads the current working directory from the
$PWDenvironment variable - If
$PWDis not set, falls back to the context’s internalcwdfield - Outputs the absolute path followed by a newline
- Always succeeds with exit code 0
Examples
Basic usage
After changing directories
With relative path navigation
In subshells
Subshells
( ) have their own working directory that doesn’t affect the parent shell.In command substitution
Saving current directory
Use Cases
Verify location before operations
Script debugging
Conditional logic based on location
Build paths dynamically
VFS Integration
Working with mounted directories
When navigating into mounted host directories,pwd shows the VFS mount point path:
pwd returns the virtual path /project, not the host path ./myproject.Multiple mount points
Environment Variables
The current working directory path. Automatically maintained by the
cd command and read by pwd.Combining with Other Commands
With cd to toggle directories
With mkdir to create in current location
With find to show absolute paths
With tree to show context
Output Format
Thepwd command always outputs:
<absolute-path> is the full path starting from /.
Exit Codes
- 0 - Always succeeds (pwd cannot fail)
Related Commands
cd- Change the current working directoryls- List contents of the current directorytree- Display directory tree from current locationfind- Search for files starting from current directory
Implementation Details
Thepwd command is implemented in /home/daytona/workspace/source/src/builtins/pwd.rs:8-16. Key implementation notes:
- Reads from
$PWDenvironment variable first - Falls back to internal context
cwdfield if$PWDis unset - Always returns exit code 0 (cannot fail)
- Takes no arguments (all arguments are ignored)
- Output always ends with a newline character
Comparison to Traditional Unix pwd
Nash’spwd is simpler than traditional Unix pwd:
| Feature | Nash pwd | Unix pwd |
|---|---|---|
-L flag (logical) | Not supported (always logical) | Supported |
-P flag (physical) | Not supported | Supported |
| Symlink resolution | N/A (VFS has no symlinks) | Resolves symlinks with -P |
| Exit codes | Always 0 | Can fail with non-zero |
Nash’s VFS doesn’t support symbolic links, so there’s no distinction between logical and physical paths.
