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?
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:
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다