The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
error in if statement capri_drm Linux 16 05-14-2008 02:00 PM
Error with if statement..Please help jisha Shell Programming and Scripting 1 01-16-2008 07:13 AM
parsing error in if statement rakeshou Shell Programming and Scripting 2 09-25-2007 10:46 AM
For loop statement - catch error lumdev Shell Programming and Scripting 4 09-20-2007 07:50 AM
tar error statement legato UNIX for Dummies Questions & Answers 3 03-29-2005 09:58 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-07-2008
dannyd_y dannyd_y is offline
Registered User
  
 

Join Date: May 2008
Posts: 9
Snytax error on If Statement--help

year=`date '+%Y'`
month=`date '+%m'`
day=`date '+%d'`
day=`expr $day - 1`

case $month in
1 | 3 | 5 | 7 | 8 | 10 | 12);;

if($day =7 ); then
$day=6
fi

4 | 6 | 9 | 11);;
if [ $day = 0 ] ; then
$day=31
fi

2);;
if [ $day = 0 ] ; then
if [ `expr $year % 4` -eq 0]; then
$day = 28
else
$day = 29
fi
fi
*) echo error: too many arguments 1>&2 ;;
esac

DATE=$year$month$day
cp $HOME/*$DATE*.log $HOME/QVGLog
cd $HOME/QVGLog
gzip *


the error message is
./call: line 9: syntax error near unexpected token `('
./call: line 9: `if($day =7 ); then'


Pls help, i've checked the syntax for if else statement on web, but cant fix it.
  #2 (permalink)  
Old 05-07-2008
dannyd_y dannyd_y is offline
Registered User
  
 

Join Date: May 2008
Posts: 9
Ok i've fixed

year=`date '+%Y'`
month=`date '+%m'`
day=`date '+%d'`
day=`expr $day - 1`

case $month in
1 | 3 | 5 | 7 | 8 | 10 | 12)
if [ $day = 7 ]
then
$day=6
fi
;;

4 | 6 | 9 | 11)
if [ $day = 0 ]
then
$day=31
fi
;;

2)
if [ $day = 0 ]
then
if [ `expr $year % 4` -eq 0]
then
$day = 28
else
$day = 29
fi
fi
;;
*) echo error: Case Statement Not Run ;;
esac

DATE=$year$month$day
cp $HOME/*$DATE*log $HOME/QVGLog
cd $HOME/QVGLog
gzip *


now the problem is the case statement failed, the message is
error: Case Statement Not Run
cp: cannot stat `/sgxde/sgxaspecs7/*2008057*log': No such file or directory
gzip: *: No such file or directory


  #3 (permalink)  
Old 05-07-2008
frank_rizzo frank_rizzo is offline Forum Advisor  
Resident BOFH
  
 

Join Date: Dec 2007
Posts: 426
please post your script with the code tags to preserve indentation. This makes it much easier to read.

the case statement did not fail. You just hit the default condition. If you don't want the code after to execute then add an exit.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:04 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0