[prev] [index] [next]

Testing (cont)

Examples:

test "$msg" = "Hello"
    # does the variable msg have the value "Hello"?

test "$x" -gt "$y"
    # does x contain a numeric value larger than y?

msg="hello there"
test $msg = Hello
    # Error: expands to "test hello there = Hello"?

test "$x" -ge 10 -a "$x" -le 20
    # is the value of x in range 10..20?

test -r xyz -a -d xyz
    # is the file xyz a readable directory?
[ -r xyz -a -d xyz ]
    # alternative syntax; requires closing ]

Note: use of quotes, spaces around values/operators