Linux command
bracket 命令
文件
涉及管道、覆盖或删除,执行前请先确认路径和参数。
常用示例
Test condition (synonym for test)
[ -f [file] ] && echo "exists"
String comparison
[ "[string1]" = "[string2]" ]
Numeric comparison
[ [5] -gt [3] ]
File tests
[ -d [directory] ] && echo "is directory"
Combine conditions
[ -f [file] ] && [ -r [file] ]
说明
is the POSIX test command for evaluating conditional expressions. It's equivalent to test but requires a closing . Spaces around and are mandatory. The command returns exit status 0 (true) or 1 (false), used in if statements and conditional execution. ```bash if -f "$file" ; then echo "File exists" fi -d "$dir" && cd "$dir" ``` For bash/zsh, [[ provides an enhanced version with pattern matching and safer syntax.
FAQ
What is the bracket command used for?
is the POSIX test command for evaluating conditional expressions. It's equivalent to test but requires a closing . Spaces around and are mandatory. The command returns exit status 0 (true) or 1 (false), used in if statements and conditional execution. ```bash if -f "$file" ; then echo "File exists" fi -d "$dir" && cd "$dir" ``` For bash/zsh, [[ provides an enhanced version with pattern matching and safer syntax.
How do I run a basic bracket example?
Run `[ -f [file] ] && echo "exists"` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
Where can I find more bracket examples?
This page includes 5 examples for bracket, plus related commands for nearby Linux tasks.