Confirming Syntax - IF statement. | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Confirming Syntax - IF statement.

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-26-2008
Cameron's Avatar
Cameron Cameron is offline Forum Advisor  
Registered User
 
Join Date: Nov 2001
Last Activity: 23 October 2011, 10:07 PM EDT
Location: Brisbane, Australia
Posts: 509
Thanks: 7
Thanked 0 Times in 0 Posts
Question Confirming Syntax - IF statement.

Hi All,

Has been a while since I was last on, so I hope everyone has been doing fine.

Would like to know if the below IF statement syntax is correct for a ksh environment. It's been pushed into live as someone had deleted the development copy(!); not withstanding that, the statement now won't be called/executed until May 5th. So if there is any obvious issues seen, I'll have time to fix.

Any/all feedback appreciated.

Cheers,
Cameron
Code:
if [ \( "${MKT}"="PU" -o "${MKT}"="PH" \) -a "${FILETYPE}"="PAY" ] ; then
  cp ${FTP_DIR}/${MKT}-${DOR}.BANKHOLIDAY \
     ${FTP_ARC}/${MKT}-${DOR}-${FILETYPE}.BANKHOLIDAY
else
  mv ${FTP_DIR}/${MKT}-${DOR}.BANKHOLIDAY \
     ${FTP_ARC}/${MKT}-${DOR}-${FILETYPE}.BANKHOLIDAY
fi

Sponsored Links
    #2  
Old 03-26-2008
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
 
Join Date: Feb 2006
Last Activity: 24 October 2014, 6:58 PM EDT
Location: Almerķa, Spain
Posts: 777
Thanks: 24
Thanked 110 Times in 105 Posts
This way is clearer for me:

Code:
if [ "${MKT}"="PU" -o "${MKT}"="PH" ] && [ "${FILETYPE}"="PAY" ]
then
     cp ${FTP_DIR}/${MKT}-${DOR}.BANKHOLIDAY \
     ${FTP_ARC}/${MKT}-${DOR}-${FILETYPE}.BANKHOLIDAY
else
  mv ${FTP_DIR}/${MKT}-${DOR}.BANKHOLIDAY \
     ${FTP_ARC}/${MKT}-${DOR}-${FILETYPE}.BANKHOLIDAY
fi

Sponsored Links
    #3  
Old 03-26-2008
Cameron's Avatar
Cameron Cameron is offline Forum Advisor  
Registered User
 
Join Date: Nov 2001
Last Activity: 23 October 2011, 10:07 PM EDT
Location: Brisbane, Australia
Posts: 509
Thanks: 7
Thanked 0 Times in 0 Posts
Thanks for the reply Klashxx.

I assume that if I reverse the logic, the result will still remain the same ??
Code:
if [ "${FILETYPE}"="PAY" ] && [ "${MKT}"="PU" -o "${MKT}"="PH" ]

Just thinking of others who will need to read it (more pedantic than anything else I guess).
    #4  
Old 03-26-2008
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
 
Join Date: Feb 2006
Last Activity: 24 October 2014, 6:58 PM EDT
Location: Almerķa, Spain
Posts: 777
Thanks: 24
Thanked 110 Times in 105 Posts
Yep , it will produce the same result.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
complex if statement syntax without using 'if ..' keyword in ksh. kchinnam Shell Programming and Scripting 4 03-15-2011 02:51 PM
Syntax error in script with if statement Straitsfan Shell Programming and Scripting 3 12-03-2010 10:39 PM
if statement code syntax Bengel UNIX for Dummies Questions & Answers 9 01-12-2010 08:18 PM
IF statement syntax in tcsh cineman Shell Programming and Scripting 6 11-03-2009 12:12 AM
syntax error on if statement apenkov Shell Programming and Scripting 6 06-01-2009 12:44 PM



All times are GMT -4. The time now is 07:43 PM.