---
title: Use read -r so backslashes in input are not treated as escapes
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Static Code Analysis (SAST) > SAST
  Rules > Use read -r so backslashes in input are not treated as escapes
---

# Use read -r so backslashes in input are not treated as escapes

{% 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/read-interprets-backslashes`

**Language:** Bash

**Severity:** Warning

**Category:** Code Style

## Description{% #description %}

The `read` builtin treats backslashes as line-continuation and escape markers unless you pass `-r` (raw). Input lines that contain backslashes can be changed or split in surprising ways. Use `read -r` (or a combined short-option token that includes `r`, such as `-re`) for normal line input, especially when reading paths or data you do not control.

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

```bash
#!/bin/bash
read line
read -p "Name? " name
read -a items
while read chunk; do
  printf '%s\n' "$chunk"
done < in.txt
read -- -r
```

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

```bash
#!/bin/bash
read -r line
read -re x
read -r -a arr
read -a arr -r
while IFS= read -r -d '' rec; do
  printf '%s\n' "$rec"
done < data.txt
read -r -- possibly_dashed_name
read
```
  Seamless integrations. Try Datadog Code SecurityDatadog Code Security 
{% icon name="icon-external-link" /%}
 