User Tools

Site Tools


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/parameter as the file to read:

while IFS= read -r line; do
  printf '%s\n' "$line"
done <<< "$var"

The same can be done in any Bourne-type shell by using a “here document” (although read -r is POSIX, not Bourne):

while IFS= read -r line; do
  printf '%s\n' "$line"
done <<EOF
$var
EOF

bash/files/read_a_file/input_source_selection.txt · Last modified: 2021/01/26 13:59 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki