Skip to main content
4 of 6
Avoid problems with file names starting with `-`.
Stéphane Chazelas
  • 584.9k
  • 96
  • 1.1k
  • 1.7k

With for and IFS:

#!/bin/bash

IFS=$'\n'       # make newlines the only separator
set -f          # disable globbing
for i in $(cat < "$1"); do
  echo "tester: $i"
done

Or with read (no more cat):

#!/bin/bash

while IFS= read -r line; do
  echo "tester: $line"
done < "$1"
wag
  • 37k
  • 13
  • 68
  • 51