Feed a String With Here-Strings

Use <<< to pass a single string to read or any stdin command.

macOSbashshellscriptingLow risk
Run read -r first rest <<< "hello world" to split the string into variables.

01Command

Command
$ read -r first rest <<< "hello world"; echo "$first"

02What it does

A here-string appends a newline and pipes the word into the command's standard input, which is shorter and safer than echo | cmd because it avoids a subshell and word-splitting surprises. It is a building block for argument parsing in scripts.

03Risk

RiskLow risk
RequirementsmacOS default zsh/bash (bash 3.2+; some features need bash 4+ via Homebrew)
CompatibilitymacOS with bash 3.2+ (GNU bash 4+ via Homebrew for advanced features)
!Warning: The string is subject to word splitting when assigned to arrays; quote expansions carefully.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

Last verified: 2026-10-13 · Category: Developer