bash:files:read_a_file:input_source_selection
Differences
This shows you the differences between two versions of the page.
bash:files:read_a_file:input_source_selection [2021/01/26 13:57] – created peter | bash:files:read_a_file:input_source_selection [2021/01/26 13:59] (current) – peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== BASH - Files - Read a file - Input source selection ====== | ====== BASH - Files - Read a file - Input source selection ====== | ||
+ | |||
+ | Usually read has a filename as its input. | ||
+ | |||
+ | To instead use the contents of a variable/ | ||
+ | |||
+ | <code bash> | ||
+ | while IFS= read -r line; do | ||
+ | printf ' | ||
+ | done <<< | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | The same can be done in any Bourne-type shell by using a "here document" | ||
+ | |||
+ | <code bash> | ||
+ | while IFS= read -r line; do | ||
+ | printf ' | ||
+ | done <<EOF | ||
+ | $var | ||
+ | EOF | ||
+ | </ | ||
+ | |||
+ | ---- | ||
bash/files/read_a_file/input_source_selection.1611669462.txt.gz · Last modified: 2021/01/26 13:57 by peter