4

I have a bash script that accepts a parameter "$input" and (among other things) directs it into a program and collects the output.

Currently my line is:

OUTPUT=`./main.exe < $input`

But I get the following error:

$input: ambiguous redirect

What is the correct way to do it?

1 Answers1

6

Your variable's value probably contains spaces.

You should double quote it:

output=$( ./main.exe <"$input" )

The bash shell requires that the variable, in this context, is quoted and will otherwise perform word-splitting and filename globbing on its value, while other shell may not require this.

Also, note that $input here is the pathname of a file that will be connected to the standard input stream of your program, not an argument to main.exe (I might have misunderstood your text, but never the less). If you want to use $input as a command line argument instead, your command would look like

output=$( ./main.exe "$input" )

Related:

Also:

Kusalananda
  • 333,661