Feed a String With Here-Strings
Use <<< to pass a single string to read or any stdin command.
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
!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
- bash.1.en.html manual pageEvidence: The bash manual page documents here-strings.
Last verified: 2026-10-13 · Category: Developer