Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The -p operator is a unary file test operator in Bash used to determine whether a specified file path exists and is a named pipe (FIFO). It evaluates the file’s metadata and returns a boolean exit status based on the file type.

Syntax

The operator can be invoked using the test builtin, the POSIX single-bracket [ ] command, or the Bash-specific double-bracket [[ ]] keyword:

# Using the test builtin
test -p /path/to/target


# Using the POSIX test command
[ -p /path/to/target ]


# Using the Bash conditional expression
[[ -p /path/to/target ]]

Technical Mechanics

  • System Call Evaluation: Under the hood, the -p operator utilizes the stat() system call to retrieve file attributes. It specifically inspects the st_mode field against the S_IFIFO bitmask to verify if the file is a First-In-First-Out (FIFO) special file.
  • Symlink Dereferencing: The operator automatically dereferences symbolic links. If the target path is a symlink, -p evaluates the ultimate target of the link rather than the symlink itself. It will return true if the symlink resolves to a valid named pipe.
  • Exit Status Codes:
    • Returns 0 (True) if the file exists and the S_IFIFO mode bit is set.
    • Returns 1 (False) if the file does not exist, if the file is of any other type (e.g., regular file, directory, character device, socket), or if the executing user lacks the necessary directory traversal (execute) permissions to resolve the path.

Negation

To test if a file is not a named pipe, the operator is prefixed with the logical NOT operator (!):
[[ ! -p /path/to/target ]]
This expression evaluates to 0 (True) if the file does not exist or if it exists but is not a FIFO.
Master Bash with Deep Grasping Methodology!Learn More