[Techtalk] Bash builtin "read" isn't working like I expect

Elizabeth Barham lizzy at soggytrousers.net
Thu Oct 30 10:55:01 EST 2003


Hi Megan,

   This appears to be a variable evaluation error with the '-' being
seen as a variable name delimiter:

  other-file=second-file.txt
  echo $other-file

results in:

  ./b.sh: line 6: other-file=second-file.txt: command not found
  -file

The key being the second line in which $other was evaluated to "" and
"-file" passed on through by echo. This works:

  other_file=second-file.txt
  echo $other_file

as does:

  other_file=second-file.txt
  first_file=first-file.txt
  while read LINE; do echo $LINE; grep $LINE $other_file; done < $first_file

Elizabeth


More information about the Techtalk mailing list