newline
The invisible character that ends a line of text, written \n in most programming languages.
In more detail
Tools that work line by line use newlines to decide where one line ends, and formats such as newline-delimited JSON put one record per line. Windows traditionally ends lines with two characters (carriage return and line feed) and Linux and macOS with one.
Examples
printf 'one\ntwo\n'find . -print0 # separates names with null bytes insteadAn SSE message ends with a double newline: "data: hi\n\n".printf 'third line\n' >> notes.txtJSON Lines puts exactly one record before each newline.A newline inside a Prometheus label value must be escaped as \n.In Terraform strings \n inserts a newline, as in "Hello from Terraform\n". terraform output -raw prints a value with no trailing newline, which is what a shell variable wants.Related terms
- newline-delimited JSON — A streaming format in which every line is one complete JSON document, so each record can be parsed as soon as it arrives.
- Server-Sent Events — A standard way for a server to keep an HTTP response open and push a stream of text events to the client, in one direction only.
- whitespace — Characters that show as blank space, such as spaces, tabs and line breaks.
- escape sequence — A backslash followed by a character that together stand for something hard to type directly, such as \n for a line break.
- null byte — The character with value zero, which can never appear inside a Unix file name and so makes a safe separator between names.
- diff — A listing of the differences between two versions of something, such as two files, two commits or two screenshots.
- printf — The command that prints text according to a format string, such as printf '%s\n' "$name".
- end — The keyword parameter of print that sets what is printed after the last argument; by default a newline.
- terraform output — The command that prints output values from state; -raw prints one bare value for a shell variable and -json prints machine-readable output for programs.
- here document — A way to write several lines of text straight into a script or file, opened with << and a marker word such as EOF and closed by that word on its own line.
Taught in
- Large Payloads And Streaming — Modern API Architecture: REST, GraphQL & gRPC
- Server-Sent Events — Modern API Architecture: REST, GraphQL & gRPC
- What Bash Does To A Line Before It Runs It — Bash Scripting & Command Line Automation
- Single Quotes, Double Quotes, Backslash — Bash Scripting & Command Line Automation
- The Unquoted Variable: Splitting And Globbing — Bash Scripting & Command Line Automation
- The Field Separator, And Reading Lines Safely — Bash Scripting & Command Line Automation
- Command Substitution And Subshells — Bash Scripting & Command Line Automation
- Script Input And Output: read, Heredocs, printf — Bash Scripting & Command Line Automation
- find And xargs — Bash Scripting & Command Line Automation
- Server-Sent Events: Streaming Updates & Recovery — Production Full-Stack Engineering
- A Branch Is A Moving Pointer — Advanced Git Internals & Distributed Workflows
- Structured Logging And Why Text Fails — Full-Stack Observability: Metrics, Tracing & Logging
- The Prometheus Exposition Format — Full-Stack Observability: Metrics, Tracing & Logging
- Cart Versus cart: The Data Model And What A Scrape Returns — Prometheus Certified Associate (PCA) Exam Prep
- The Print Function And String Literals — Hands-on Python: Complete Video Course & Book
- Defining Your First Function — Hands-on Python: Complete Video Course & Book
- Several Functions, And Flow Of Control — Hands-on Python: Complete Video Course & Book
- The Print Function Keyword End — Hands-on Python: Complete Video Course & Book
- Files: Writing And Reading — Hands-on Python: Complete Video Course & Book
- Installing Terraform And Meeting The CLI — Infrastructure as Code with Terraform
- Writing Your First Configuration In HCL — Infrastructure as Code with Terraform
- Return Values: Outputs And Locals — Infrastructure as Code with Terraform
- Thirty Questions, One Sneaky Print — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Print, Input And The Casts Between — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Fundamentals Sprint — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- While, For, Range And The Loop Else — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Strings: Escapes, Slices And Methods — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Characters As Numbers — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- String Methods The Exam Picks — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Streams, Handles And Open Modes — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- read, readline, errno And bytearray — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Comprehensions, Closures And Files Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Expressions And Functions: Making Configuration Compute — HashiCorp Terraform Associate (004) Exam Prep
References
- JSON Lines
- WHATWG HTML Standard: server-sent events
- POSIX definitions: newline character
- HTML Standard: Server-sent events (parsing an event stream)
- Python: string literals and escape sequences
- Python glossary: universal newlines
- Strings and templates: escape sequences