Syntax
Description
Thecat command reads one or more files and writes their contents to standard output. When called without arguments, it reads from standard input and echoes it to standard output, making it useful in pipelines.
In Nash,
cat operates entirely within the virtual filesystem (VFS). It never accesses the host system unless you’ve mounted a directory with --bind.Parameters
Path to file(s) to read. Can be relative to current directory or absolute. If omitted, reads from standard input.
Behavior
- No arguments: Reads from stdin and writes to stdout (pass-through mode)
- One or more files: Concatenates all files in order and writes to stdout
- Flags: Any arguments starting with
-are silently ignored - Error handling: If any file cannot be read, returns exit code 1 with error message
Examples
Display a single file
Concatenate multiple files
Use as stdin pass-through
Create a file from stdin
Append to a file
Error Handling
File not found
1
Permission denied (read-only mount)
cat will return an error describing the issue.
Implementation Details
- Source:
src/builtins/cat.rs - Reads entire file contents into memory using
vfs.read_to_string() - Processes files sequentially in the order provided
- Concatenates outputs without separators
- Flags starting with
-are filtered out but not validated
Differences from Unix cat
| Feature | Unix cat | Nash cat |
|---|---|---|
| Multiple files | ✅ Supported | ✅ Supported |
| Stdin passthrough | ✅ Supported | ✅ Supported |
-n (line numbers) | ✅ Supported | ❌ Ignored |
-b (number non-blank) | ✅ Supported | ❌ Ignored |
-v (show non-printing) | ✅ Supported | ❌ Ignored |
-E (show line ends) | ✅ Supported | ❌ Ignored |
| Large files | Streams | Loads into memory |
