file-test
Bash -t — terminal descriptor test
Checks whether an open numeric descriptor is attached to a terminal. Use it to decide whether interactive presentation is appropriate, not to infer whether the shell itself is interactive. The fixture redirects a descriptor to a regular file, so it is false even if the caller is at a terminal. Run the example independently in a fresh private directory. Expected output (one item per line): file=1; closed=1.
Formal Syntax & Structure
bash syntaxbash
[[ -t fd ]]Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| fd | integer | Open file descriptor number. |
Return Value
exit status
0 for a true condition; 1 for a false condition. Invalid expressions may fail differently.
Working Example
Example Snippetbash
exec 3> output.txt[[ -t 3 ]]; printf 'file=%s\n' "$?"exec 3>&-[[ -t 3 ]]; printf 'closed=%s\n' "$?"