file-test

Bash -S — Unix socket pathname test

Identifies a socket filesystem entry. A true result does not establish that a server is listening or responsive. The Linux fixture uses Python 3 to bind an AF_UNIX socket in the private directory, closes it without accepting any connection, then inspects the remaining pathname. Run the example independently in a fresh private directory. Expected output (one item per line): socket=0; regular=1.

Formal Syntax & Structure

bash syntaxbash
[[ -S path ]]

Parameters & Attributes

NameTypeDescription
pathpathFile or directory pathname to inspect.

Return Value

exit status

0 for a true condition; 1 for a false condition. Invalid expressions may fail differently.

Working Example

Example Snippetbash
python3 -c 'import socket; s=socket.socket(socket.AF_UNIX); s.bind("local.sock"); s.close()' || exit 1[[ -S local.sock ]]; printf 'socket=%s\n' "$?"touch ordinary[[ -S ordinary ]]; printf 'regular=%s\n' "$?"
Bash Reference