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 -S operator is a unary file test operator in Bash used to determine whether a specified file path exists and is a socket (specifically, a Unix domain socket). When evaluated within a conditional expression, it returns a boolean exit status based on the file’s type metadata in the filesystem. Syntax
[ -S "$FILE_PATH" ]
[[ -S "$FILE_PATH" ]]
test -S "$FILE_PATH"
Evaluation Rules
  • True (Exit Status 0): The path exists, the executing user has the necessary search permissions to resolve the path, and the target inode represents a socket (identified by the S_IFSOCK file type constant).
  • False (Exit Status 1): The path does not exist, the path resolves to a different file type (e.g., regular file, directory, block device, FIFO), or the executing user lacks permissions to resolve the path.
Technical Characteristics
  • Symlink Resolution: The -S operator follows symbolic links. If the target path is a symlink, the operator evaluates the ultimate target of the link, not the symlink itself. To test if a symlink itself is a socket (which is technically impossible as symlinks and sockets are mutually exclusive inode types), the -h or -L operators must be used instead.
  • POSIX Compliance: The test -S and [ -S ] constructs are defined in the POSIX.1 standard, ensuring cross-shell compatibility (e.g., sh, dash, zsh). The [[ -S ]] construct is a Bash-specific extended test keyword that executes the same underlying filesystem check but is parsed differently by the shell interpreter, preventing word splitting and pathname expansion.
  • System Call Implementation: Under the hood, Bash utilizes the stat() system call to retrieve the file’s mode. It then applies a bitwise mask (typically via the S_ISSOCK(m) macro in C) against the st_mode field of the returned stat struct to verify the socket file type.
Master Bash with Deep Grasping Methodology!Learn More