Skip to content

fix(redirect): 2>/dev/null does not suppress stderr from builtins #1116

@chaliy

Description

@chaliy

Summary

Redirecting stderr to /dev/null via 2>/dev/null does not suppress error output from builtin commands. The stderr content still appears on the terminal.

Reproduction

echo "error msg" 2>/dev/null
# Expected: "error msg" on stdout only, stderr suppressed
# Actual: works for echo (stdout), but...

ls /nonexistent 2>/dev/null
# Expected: no output
# Actual: error message still visible

Also affects &> combined redirect:

ls /nonexistent &> /dev/null
# Expected: no output at all
# Actual: error still shows (exit code 2 is correct)

Context

Discovered while running bashblog via bashkit CLI. Bashblog uses &> /dev/null and 2>/dev/null extensively to suppress expected errors:

  • ls ./*.html &> /dev/null
  • cp .backup.tar.gz .yesterday.tar.gz &> /dev/null
  • rm ./"$prefix_tags"*.html &> /dev/null

Expected behavior

2>/dev/null should discard all stderr output. &>/dev/null should discard both stdout and stderr.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions