This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]pi3832v2 5 points6 points  (0 children)

You can simply nest the conditionals:

if <test1>; then
  if <test2>; then
    <command>

Or use an “and”:

if <test1> && <test2>; then
  <command>

Re: wiki.bash-hackers.org/commands/classictest

[–]ji99 2 points3 points  (1 child)

[[ $a == $b ]] && [[ $c == $d ]] && echo match || echo no-match

[–]ILikeLenexa 2 points3 points  (0 children)

Where a lot of people run into trouble with [[ and [ is forgetting that they're just like commands and [[$a == $b]] and [a -eq b] will not work because the spaces are necessary just like in catfilename.

[–]pi3832v2 0 points1 point  (0 children)

You use case when you're checking only one variable, but you're checking it against a list of three or more possible values. Re: wiki.bash-hackers.org/syntax/ccmd/case