labradorchik
asked on
ERROR message in the Unix bash shell script. Any comments?
I am running my SAS program in within Unix bash script shell script and getting the following message =>
Syntax error: unexpected end of file
I checked everything in the script and looks like it's correct. I did some research online, but this error is very common and may mean different error problems.
Please let me know if you see anything in this script incorrect.
Syntax error: unexpected end of file
I checked everything in the script and looks like it's correct. I did some research online, but this error is very common and may mean different error problems.
Please let me know if you see anything in this script incorrect.
mydir=/start/dir
plog=/start/log
filename=sasprog1.log
search=ERROR
outfile=file1.txt
sas=/products/SAS/SASFoundation/9.2/sas
$sas $mydir/sasprog1.sas >$plog/$filename
find $plog -type f -name $filename |while read file
do
RESULT= `grep $search $file`
if [["$RESULT" ==""]];
then
echo "Error(s) in $file: $RESULT" >> $outfile
fi
done
exit 0
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oh, seems I didn't look close enough!
As opposed to [[ ]] where spaces are required, spaces arund "=" when assigning variables are forbidden:
RESULT= `grep $search $file`
change to
RESULT=`grep $search $file`
As opposed to [[ ]] where spaces are required, spaces arund "=" when assigning variables are forbidden:
RESULT= `grep $search $file`
change to
RESULT=`grep $search $file`
seems a bit overkill to use find for only one file?
if [ -f $file ]
then
....
fi
should do the trick to test for a single file...
or you may need some wildcarding added to the -name $filename part.
The above doesn't apply if /start/log is actualy a whole tree of directories with some or all containing a file named sasprog1.log
if [ -f $file ]
then
....
fi
should do the trick to test for a single file...
or you may need some wildcarding added to the -name $filename part.
The above doesn't apply if /start/log is actualy a whole tree of directories with some or all containing a file named sasprog1.log
Just a tip about your "I checked everything in the script", when debugging a script, you can see the verbose output of your script like this:
sh -xv <your script>
This will let you see at what line and when the error appears, more importantly: you can see how variables are assigned and how tests are evaluated.
sh -xv <your script>
This will let you see at what line and when the error appears, more importantly: you can see how variables are assigned and how tests are evaluated.
ASKER
After making all these changes, I am still expiriencing this
ERROR: unexpected end of file
Anyone else would like to comment on my code or this error before I close this question today?
ERROR: unexpected end of file
Anyone else would like to comment on my code or this error before I close this question today?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
When using "bash -xv <your script>" - where do you get the error? Run your script like this and post the part where you get the error message. Thanks.
ASKER
When I am using "bash -xv <my script>", - I get my error "ERROR: unexpected end of file" at the end of the script (the very last line with "exit 0").
Please note: when I run my sas program (sasprog1.sas) by itself, - it works fine. I do not get any error messages and I can see that I am using correct input files and producing a correct output data.
I just noticed that my sas log file (sasprog1.log) is totaly empty. I am not sure why is this happening??
Below is the part where my sas log file is created. I know that sas log is created automaticaly, but I am only doing this if for example a sas log will have a different name than my sas program, beacuse I still have to search my sas log for some errors.
Is my script wrong?
Please note: when I run my sas program (sasprog1.sas) by itself, - it works fine. I do not get any error messages and I can see that I am using correct input files and producing a correct output data.
I just noticed that my sas log file (sasprog1.log) is totaly empty. I am not sure why is this happening??
Below is the part where my sas log file is created. I know that sas log is created automaticaly, but I am only doing this if for example a sas log will have a different name than my sas program, beacuse I still have to search my sas log for some errors.
$sas $mydir/sasprog1.sas >$plog/$filename
Is my script wrong?
As i said before bash ( the script interpreter) doesn't use uppercase ERROR: in some error message more like:
bash: script: end of file.... [ only lowercase ]
f.e. the next script
Create a file t.sh:
(echo followed by a single double quote)
when run with bash t.sh will yield an error like:
t.sh: line 1: unexpected EOF while looking for matching `"'
t.sh: line 2: syntax error: unexpected end of file
So the error must be from SAS, what does SAS say when the inputscript cannot be found?
bash: script: end of file.... [ only lowercase ]
f.e. the next script
Create a file t.sh:
echo "
(echo followed by a single double quote)
when run with bash t.sh will yield an error like:
t.sh: line 1: unexpected EOF while looking for matching `"'
t.sh: line 2: syntax error: unexpected end of file
So the error must be from SAS, what does SAS say when the inputscript cannot be found?
ASKER
I am not sure what I am doing wrong, but I am still keep getting this error...
line 18: syntax error: unexpected end of file - all in lower case
line 18 is the last line and this line is blank (next line after "exit 0").
I can run SAS program fine, - input and output files are correct and are showing up in my directories, but when I run my script with SAS program, I am still getting this error.
The only thing that I can tell is wrong is my SAS log file (sasprog1.log), because it is blank.
What else can it be??
line 18: syntax error: unexpected end of file - all in lower case
line 18 is the last line and this line is blank (next line after "exit 0").
I can run SAS program fine, - input and output files are correct and are showing up in my directories, but when I run my script with SAS program, I am still getting this error.
The only thing that I can tell is wrong is my SAS log file (sasprog1.log), because it is blank.
What else can it be??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
labradorchick, you script has changed from the original, as it now gives a different message, can you show the script along with the error message? Possibly the changes to the procedure added some new issues.
ASKER
Thank you!!
This error message is not appearing anymore. I was missing the following:
This error message is not appearing anymore. I was missing the following:
export mydir
export plog
ASKER