I have a file named open. I open up a terminal, read it's first line into a variable text and tried to put all the contents of file except for text in a new file called open.temp using grep's pattern inversion. Here's the code:papagolf@Sierra ~/My Files/My Programs % cat open# PPPPQQQQRRRRSSSSpapagolf@Sierra ~/My Files/My Programs % text=`head -n 1 open`papagolf@Sierra ~/My Files/My Programs % cat open | grep -v $text > open.temppapagolf@Sierra ~/My Files/My Programs % cat open.temp QQQQRRRRSSSSBut when I put the same commands in a file called test.sh, give it executable permission and execute it, it pops an error.papagolf@Sierra ~/My Files/My Programs % rm open.temppapagolf@Sierra ~/My Files/My Programs % touch test.shpapagolf@Sierra ~/My Files/My Programs % nano test.sh  papagolf@Sierra ~/My Files/My Programs % chmod +x test.sh papagolf@Sierra ~/My Files/My Programs % ./test.sh grep: PPPP: No such file or directorypapagolf@Sierra ~/My Files/My Programs % cat test.sh text=`head -n 1 open`cat open | grep -v $text > open.tempSorry if this question is trivial but I'm new to bash and I couldn't get my head around this problem. Can someone explain it?
Inconsistent behavior of Bash
bash;grep;io redirection