Hello all,
I am trying to write a simple script that will parse through a text/properties file and check a couple of if statements.
Here is what I have so far:
FILENAME=$1
while read line
do
echo $line
done < $FILENAME
When I call ./simple.sh testfile.txt I recieve a file or directory cannot be found.. I know it is something increadibly simple that I am missing.
Thanks,
Lammy
See what happens when you do the following:
ls -l ./simple.sh
ls -l testfile.txt
bash is correct, you don't have such file. Example :
I will create file called "test.txt" with "test123" string in it.
your script will look like this :
FILENAME=$1
while read line
do echo test
echo $line
done < $FILENAME
and run :
All,
If I do an ls -l both files are in the same directory.
Here is what I do to run my simple.sh
./simple.sh test[Tab Complete]
which gives me
./simple.sh test.txt
if I can tab complete it.. i believe it is in the same directory.
I put in the followin code
FILENAME=$1
while read line
do echo test
echo $line
done < $FILENAME
output was
./simple.sh: line 19: test.txt: No such file or directory
All really good suggestions but I think that there might be something else a miss on this extremely simple script...
Lamagra,
As you can see in the error message, the shell is pointing to
line number 19.
Why don't you display the entire script?
You know shell thats a really good idea..
Sorry all I guess it would have been a little more beneficial if I would have done that the first.
#!/bin/bash
cd /test/me/i/am/a/noob/ie
#COUNTER=0
#while [ $COUNTER -lt 2 ]; do
command that lives in IE directory
#done
FILENAME=$1
while read line
do
echo test
#echo $line
done < $FILENAME
I see the problem now that I have pasted it in here. Because i do a cd to be able to run the command that lives in the ie directory. Doing this changes where I am pointing to and would not recognize the test.txt file.
How do I use the command in ie (directory) without cding?
Can I set it to a variable such as:
COMMAND_PATH=/test/me/i/am/a/noob/ie
$COMMAND_PATH/COMMAND ARGS
You all were right.
It was because I was cding to the different directory which was taken me out of scope for that file.
What I did was created variable that held the path of the command.
Then I just used the variable and passed the args to it which allowed me to keep the scope to pass the text file.
Thanks for all of your help,
Lammy