The UNIX and Linux Forums  


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
Reading specific contents from 1 input files and appending it to another input file sksahu Shell Programming and Scripting 5 01-14-2009 06:09 AM
How is use sselect statement o/p in insert statement. nkosaraju Shell Programming and Scripting 2 08-06-2008 10:26 PM
If statement - How to write a null statement april Shell Programming and Scripting 3 04-16-2008 02:14 PM
If statement ROOZ UNIX for Dummies Questions & Answers 3 03-09-2008 12:57 PM
How to prompt for input & accept input in ONE line newbie168 Shell Programming and Scripting 2 09-27-2005 06:02 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-21-2009
venhart venhart is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 39
if statement with $1 input

Hi,

Please could someone advise me what I'm doing wrong here ?
( I'm using bourne shell - sh )

if
$1=BillingReport01
then
STARTUP_LOG=/Gateway01/FIXGW/var/log/logwatcher_$1.startup.$DATE.log
elif
$1=BillingReport02
then
STARTUP_LOG=/Gateway02/FIXGW/var/log/logwatcher_$1.startup.$DATE.log
fi

regards,

venhart
  #2 (permalink)  
Old 01-21-2009
Gee-Money Gee-Money is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 48
You need the "test" construct, like so:


Code:
if [ $1 = something ]
 then
 do some stuff
elif [ $1  = something_else ]
 do some other stuff
fi

the "[]" brackets are where the test/comparison needs to take place.
  #3 (permalink)  
Old 01-21-2009
methyl methyl is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1,184

Code:
As posted there are syntax errors. The syntax for if would normally start
if [ condition ]
then

It is best to save the script parameter $1 into a named variable at the earliest opportunity.
On some unixes the variable "DATE" is reserved. You do not seem to be setting the variable.

This type of processing is easier to follow with a case statement.

In this example I have replaced $DATE with $YYYYMMYY - the reversed date. Your version will of course be different.
Beware that if the process is run more than once per calendar day the filename is not unique.


Billing="$1"
YYYYMMDD="`date +%Y%m%d`"
#
#
case "${Billing}" in
        "BillingReport01")
        STARTUP_LOG="/Gateway01/FIXGW/var/log/logwatcher_${Billing}.startup.${YYYYMMDD}.log"
        ;;
        "BillingReport02")
        STARTUP_LOG="/Gateway02/FIXGW/var/log/logwatcher_${Billing}.startup.${YYYYMMDD}.log"
        ;;
        *)
        echo "Invalid Billing Parameter: ${Billing}"
        exit
        ;;
esac
#
echo "${STARTUP_LOG}"


Last edited by methyl; 01-21-2009 at 09:23 AM.. Reason: too wide
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 12:25 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