Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if-then-else correct?

Status
Not open for further replies.

jawon

Programmer
Feb 6, 2003
31
US
Is there something wrong with this statement? The variables come out ok and the files they reference do indeed exist, but when this runs, it jumps to the else statement.

if [ -f $mbdir/v${lastmon}${lastyear}.sas7bdat.gz ] and [ -f $mydir/logs/regcsr_20${year}-${month}-01.txt ] and [[ $day <= 10 ]]
then ghcsas $mydir/rvmetr.sas
else echo &quot;All necessary files do not exist. This sas program did not run.&quot;
fi
 
what's that 'and' are ??
try to configure the value of 'else' ??
make it clear, use a if-cascade not an if-orgie,
try 'case' it's really simpler and efficace.
 
Try:

[tt]if [[ -f $mbdir/v${lastmon}${lastyear}.sas7bdat.gz && -f $mydir/logs/regcsr_20${year}-${month}-01.txt && $day <= 10 ]]
then ghcsas $mydir/rvmetr.sas
else echo &quot;All necessary files do not exist. This sas program did not run.&quot;
fi[/tt]

As iribach pointed out, using &quot;and&quot; is not a valid syntax. Your statement was also using two types of &quot;test&quot;, [, which behaves like /usr/bin/test, and [[, which is the Korn shell built-in version. The above achieves the same using only one test, which should also be more efficient. Annihilannic.
 
Oops, one mistake:

[tt]if [[ -f $mbdir/v${lastmon}${lastyear}.sas7bdat.gz && -f $mydir/logs/regcsr_20${year}-${month}-01.txt && $day -le 10 ]]
then ghcsas $mydir/rvmetr.sas
else echo &quot;All necessary files do not exist. This sas program did not run.&quot;
fi[/tt]

You can't use &quot;<=&quot; to compare integers in this example, you need to use -le instead.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top