๐ก Bash Script if Statements: Compare Operators โ Executive Summary
Technical architectural analysis, practical configuration manifests, and deployment instructions for Bash Script if Statements: Compare Operators.
if
| Expression | Use | Features | POSIX Compatibility |
if
|
Branch based on command execution result | Judging by the exit code after executing the command | fully compatible |
if [
|
Basic conditional expression evaluation | Use external command test, space strict | POSIX standard |
if [[
|
Extended conditional expression evaluation | More flexible and safer, string pattern matching possible | Bash/Zsh only (incompatible) |
if ((
|
Evaluation of arithmetic conditional expressions | Dedicated to arithmetic expressions, optimized for integer operations and comparisons, built-in | Bash/Zsh only (incompatible) |
Features
POSIX std
bash
# ๋น ์กฐ๊ฑด
if [ -z "$1" ]; then
echo "๋น์์"
fi
if [ -n "$1" ]; then
echo "๋น์ด์์ง ์์"
fi
bash/zsh
bash
# ์ผํญ์ฐ์ฐ์
BOOL=$( [[ <์กฐ๊ฑด๋ฌธ ์ฝ์
> ]] && echo "true" || echo "false" )
# ๋ฌธ์์ด์ด ํน์ ๋ฌธ์์ด์ ํฌํจํ๋์ง ํ์ธ
if [[ "$ORIGIN" == *"MyString"* ]]; then
echo "๋ฌธ์์ด์ด ํฌํจ๋์ด ์์ต๋๋ค."
else
echo "๋ฌธ์์ด์ด ํฌํจ๋์ด ์์ง ์์ต๋๋ค."
fi
# ๊ฐ์
if [[ "$COMPLETION" -eq 1 ]]; then
fi
ETC
bash
# sudo/root ํ์ธ
if [[ $EUID -eq 0 ]]; then
echo "sudo/root ๊ถํ์
๋๋ค."
fi




Leave a Reply