I have this simple script:
#!/bin/bash
cmd="file.txt"
while read line
do
command $line > $line
done < $cmd
And this .txt file:
./cmd var1 var2 var3
./cmd var1 var2 var3
./cmd var1 var2 var3
./cmd var1 var2 var3
My goal is to read each line and execute the command, but I keep getting this error:
line x: $line: ambiguos redirect
I am new to BASH and I have no idea what this error means and while researching it, dozens of various explanations came up. Does any1 have an idea what I could be doing wrong?
What you’re executing is essentially:
The shell can’t figure out which file you want the output to redirect to:
var1,var2, orvar3I’m not certain what you’re trying to do, but if you want to output to, say
var1, then you could do:However, if–as your post says–you only want to execute the command, then you don’t need redirection at all. Simply do: