For a literal text line, use IFS= read -r value. The empty IFS avoids trimming field-separator whitespace and -r prevents backslash processing by read. Quote the later expansion as well.
Reproduce in an empty temporary directory
This isolated example creates only fixture data in its working directory or runs local JavaScript. Run it separately from your project so the named files cannot overwrite real work.
printf '%s\n' ' C:\demo\new ' > input.txt
IFS= read -r exact < input.txt
read altered < input.txt
printf 'exact: <%s>\n' "$exact"
printf 'altered: <%s>\n' "$altered"
test "$exact" = ' C:\demo\new '
test "$exact" != "$altered"Observed local output
exact: < C:\demo\new >
altered: <C:demonew>What to compare
The two variables come from the same file, but their contracts differ. The raw read preserves the leading spaces, trailing spaces and backslashes. A subsequent echo can introduce another interpretation layer depending on the shell, so the fixture uses a literal printf format. The angle brackets make boundary whitespace visible without changing the stored value.
Choose the next action
Decide whether the input is a raw line or a set of fields. Apply IFS and read options at the read operation rather than globally changing shell parsing. For configuration records, compare a known sample containing spaces and backslashes before processing real files. For a loop, preserve the same raw-read settings for every line and handle a final unterminated line according to your file contract. If the input is a path, quote it again when passing it to the command that opens the file.
Limits and verification
This example handles one newline-terminated text record. It is not a CSV parser and does not define escaping for a structured file format. A read can return a failure status at EOF while still assigning a partial final record; see the related guide for that separate boundary. Do not add eval to recover characters: it would reinterpret data as shell code.
Related: Bash Read Skips the Last Line: Preserve a Partial Record at EOF.
Isolated example executed on macOS on November 10, 2026 (KST), using Bash 3.2, Python 3 for the byte fixture, and Node v26.5.0. Results describe the example, not your application or every runtime version.