---
title: Avoid combining test operators with -a or -o
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Static Code Analysis (SAST) > SAST
  Rules > Avoid combining test operators with -a or -o
---

# Avoid combining test operators with -a or -o

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site.md). ().
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**ID:** `bash-code-quality/ambiguous-compound-test-operators`

**Language:** Bash

**Severity:** Warning

**Category:** Code Style

## Description{% #description %}

Inside `[ ... ]`, combining expressions with `-a` (logical and) or `-o` (logical or) is easy to get wrong: POSIX marks those XSI combining operators as obsolescent and notes that many such expressions are ambiguously defined. Precedence also differs from shell `&&` and `||`.

It is better to chain separate bracket tests with shell logical operators. For example, replace `[ -f file -a -r file ]` with `[ -f file ] && [ -r file ]`. In Bash, you can also use `[[ ... ]]` and combine conditions with `&&` or `||` instead of `-a` and `-o`.

## Non-Compliant Code Examples{% #non-compliant-code-examples %}

```bash
#!/bin/bash
[ a = b -a c = d ]
[ x -o y ]
[ x = y -o z = w ]
```

## Compliant Code Examples{% #compliant-code-examples %}

```bash
#!/bin/bash
[[ a && b ]]
[[ -a file ]]
[ -a file ]
[ -e foo ]
[ x = y ]
[ x = y ] && [ z = w ]
```
  Seamless integrations. Try Datadog Code SecurityDatadog Code Security 
{% icon name="icon-external-link" /%}
 