I have a very basic shell script right now, and I am trying to run grep from inside of it. It looks like this:
#!/bin/sh
filename=$1
echo "The program that you will be editing is called $filename"
grep "//" $filename
The name of said file is "myscript" for right now. I am executing it on the command line as follows:
sh myscript test.txt
It SHOULD output the first three lines of the text file, since they are preceded with // style comments, which is what I am looking for. It should look like the following:
// Some text
// Some more text
// Some more text
I know it should look like that because when I run
grep "//" test.txt
outside of the script, it displays. From inside the script, I get this error:
The program that you will be editing is called test.txt
grep: can't open test.txt
I'm not sure what I'm doing wrong... I also want to mention that when I put "test.txt" inside the script instead of "$filename", it runs perfectly, so I KNOW it has to be with the variable, but what is it that I messed up?
For added information, the primary shell is tcsh and the shell I am trying to run the script in is sh, if that makes a difference.
Thanks in advance.