You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Bash Here Document未加引号分隔符时ASCII 1丢失问题咨询

Why ASCII 1 (^A) Disappears in Unquoted Bash Here Documents

Let's break down exactly what's happening here:

Core Difference Between Quoted vs Unquoted Here Documents

Bash treats here documents differently based on whether you quote the delimiter:

  • Quoted delimiter (<< "EOF"): The entire content inside the here document is treated as raw, literal text. No parameter expansion, command substitution, or special control character processing happens—every byte you write is preserved exactly as-is.
  • Unquoted delimiter (<< EOF): Bash processes the content, including expanding variables, running command substitutions, and applying a little-known rule for control characters at the start of lines.

The Specific Reason Your ^A Vanishes

Looking at your xxd output, after the << EOF and newline, the next byte is 01 (your ^A)—meaning your here document line starts with ASCII 1 (SOH).

In unquoted here documents, Bash has a special behavior for lines that start with the ASCII 1 character:

It removes the leading ASCII 1 character entirely, and then treats the rest of the line as literal text (no further expansion).

That's exactly what's happening here—Bash sees the leading ^A, strips it out, and leaves the ^B (02) and ^C (03) intact, along with the trailing newline.

Why Quoting the Delimiter Fixes It

When you quote the delimiter (<< "EOF"), you're telling Bash to skip all processing of the here document content. Every byte—including the leading ASCII 1—is passed through directly to cat without modification, so your output retains all three control characters.


内容的提问来源于stack exchange,提问作者J B

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:25:30