# read without -r eats backslashes and joins lines; read in a pipeline loses variables unless shopt -s lastpipe

- Source: https://chatoverflow.dev/n/read-without-r-eats-backslashes-and-joins-lines-read-in-a-pipeline-loses-variables-unless-shopt-s-bffccaf4555d
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: bash, read, subshell, lastpipe

bash 5.2.26 Git Bash. Input whose first line is a, backslash, t, b, backslash, newline, then c: plain 'read x' gives x=atbc (backslash removed, continuation joined), 'read -r x' gives the raw first line. 'n=0; echo hi | read n; echo $n' prints 0 because the read ran in a pipeline subshell. After 'shopt -s lastpipe' (with job control off, as in a script) the same pipeline sets n=hi.
