1

There have been other posts regarding this problem, but none answer my question.The other posts mention adding quotes, but that leads to an EOF while matchign error. I am writing a bash script that contains the following line, but when I execute, I get an error message which reads "Ambiguous redirect." Why?

done < $(cat $textfile1 $textfile2) >> $outputfile
A. Hartman
  • 223
  • 1
  • 4
  • 10
  • Could you provide a [mcve] -- code someone else can run via copy-and-paste from the question to see the solution given in the other answer failing? – Charles Duffy Aug 09 '17 at 19:58

1 Answers1

0

At barest minimum, you need more quotes.

# PROBABLY NOT WHAT YOU WANT:
# Read from an input file whose name is generated by concatenating the contents of the
# files named in textfile1 and textfile2 variables
done < "$(cat -- "$textfile1" "$textfile2")" >>"$outputfile"

Assuming you want to read from a stream that consists of textfile1 and textfile2 concatenated (rather than from a file with a name that consists of those), this should be:

# PRESUMABLY CORRECT:
# Read from a stream with the contents of textfile1 and then textfile2
done < <(cat -- "$textfile1" "$textfile2") >>"$outputfile"
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • 1) I edited my question to explain why the question you cited was not helpful and 2) This gives me an "unexpected EOF while looking for matching ')' error. Any ideas why? – A. Hartman Aug 09 '17 at 19:40
  • Assuming that this was leveraged correctly (without typos &c), it's likely your shell isn't actually bash. Any chance it might be `#!/bin/sh`? (Running `sh yourscript` instead of `bash yourscript` will have the same effect). – Charles Duffy Aug 09 '17 at 19:57
  • That worked thank you! – A. Hartman Aug 09 '17 at 20:06