---
title: Prefer dollar parens over backticks for command substitution
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Static Code Analysis (SAST) > SAST
  Rules > Prefer dollar parens over backticks for command substitution
---

# Prefer dollar parens over backticks for command substitution

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com, us2.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/no-old-style-command-substitution`

**Language:** Bash

**Severity:** Notice

**Category:** Best Practices

## Description{% #description %}

This rule flags the use of old-style command substitution (``command``) and encourages the use of the alternative form (`$(command)` instead).

Backtick command substitution has several drawbacks: it has undefined behavior with quoting in POSIX, uses a custom escaping mode that can produce surprising results, and is difficult to nest (e.g. nesting backticks requires escaping inner backticks). The `$(...)` form avoids these issues, is specified by POSIX, and is supported by all common shells (bash, ksh, etc.). It also makes nested command substitution straightforward, as in `$(outer $(inner))`.

To comply with this rule, replace every backtick command substitution with the equivalent $(…) form. For example, write `echo "You are running on $(uname)"` instead of `echo "You are running on \`uname`"`, and`dir=$(dirname "$file")`instead of `` dir=`dirname "$file"```. The behavior is the same; only the syntax changes. Tools like shfmt can convert backticks to`$(…)` automatically.

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

```bash
#!/bin/bash
echo "You are running on `uname`"
```

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

```bash
#!/bin/bash
echo "You are running on $(uname)"
```
  Seamless integrations. Try Datadog Code SecurityDatadog Code Security 
{% icon name="icon-external-link" /%}
 