I have this script:
while read line; do
done < "$1"
I am a proud sentence.
chmod +x ./testScript.txt
./testScript.txt < ./file.txt > output.txt
./testScript.txt: line 11: $1: ambiguous redirect
$1 isn't defined because you haven't passed an argument to your script; you've redirected its input. Either call your script as
./testscript.txt ./file.txt > output.txt
or, better yet, just let your script read from standard input:
while read line; do ... done
When you call
./testScript < ./file.txt > output.txt, your
while loop will read from its standard input, which is inherited from
./testScript, which reads from