if statement with $1 input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting if statement with $1 input
# 1  
Old 01-21-2009
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  
Old 01-21-2009
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  
Old 01-21-2009
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash read input in case statement not working as expected

I'm having an issue with bash read input when using a case statement. The script halts and doesn't read the input on the first loop. if I hit enter then the scripts starts to respond as expected. Need some help here. defaultans=8hrs read -e -i $defaultans -p "${bldwht}How long would you like... (5 Replies)
Discussion started by: woodson2
5 Replies

2. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

3. Shell Programming and Scripting

Update Statement User menu input screen

Hi Guys, Any good reference for me to perform user database update statement on table which has quite number of fields could be updated depend on user specified column name and the value to assign. All the approaches are welcome and appreciated. Thanks. (1 Reply)
Discussion started by: ckwan123
1 Replies

4. Shell Programming and Scripting

Read input files and merge them in given order and write them to input one param or one file

Dear Friends, I am looking for a shell script to merge input files into one file .. here is my idea: 1st paramter would be outfile file (all input files content) read all input files and merge them to input param 1 ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
Discussion started by: hyd1234
4 Replies

5. Shell Programming and Scripting

Trouble in getting user input while using CASE statement in UNIX

i want to get user input like this please tell which option to chose 1. mango 2. tango 3. rango if user chooses mango then it should execute a set of statements and again ask like this what do you want to do 1.add 2.subtract 3.exit when i choose exit it should goto my previous menu... (4 Replies)
Discussion started by: s.deepak
4 Replies

6. Shell Programming and Scripting

!!VERY URGENT!! Trouble in getting user input, while using under CASE statement in UNIX

i want to get user input like this please tell which option to chose 1. mango 2. tango 3. rango if user chooses mango then it should execute a set of statements and again ask like this what do you want to do 1.add 2.subtract 3.exit when i choose exit it should goto my previous... (1 Reply)
Discussion started by: s.deepak
1 Replies

7. Shell Programming and Scripting

redirect input within case statement?

I'm trying to run the logic below but get a `<' is not matched error message when I return a Y or y; printf "Run this ? : " read RESP case $RESP in Y|y) cat <<EOF > file today is Monday EOF ;; N|n) exit 1 ;; esac Any ideas? (2 Replies)
Discussion started by: h8mmer
2 Replies

8. Shell Programming and Scripting

KSH - How to use a file as input to an IF or AWK statement

Hi, I have a ksh script where I have an awk statement to exclude a few items... but my "few items" has now grown substantially and I'm looking for a nice compact way of doing this. Maybe putting the exceptions into a file or something? Any suggestions greatly appreciated. # Excluded items... (1 Reply)
Discussion started by: right_coaster
1 Replies

9. Shell Programming and Scripting

How is use sselect statement o/p in insert statement.

Hi All, I am using Unix ksh script. I need to insert values to a table using the o/p from a slelect statement. Can anybody Help! My script looks like tihs. ---`sqlplus -s username/password@SID << EOF set heading off set feedback off set pages 0 insert into ${TB_NAME}_D... (2 Replies)
Discussion started by: nkosaraju
2 Replies

10. Shell Programming and Scripting

If statement - How to write a null statement

In my ksh script, if the conditions of a if statement are true, then do nothing; otherwise, execute some commands. How do I write the "do nothing" statement in the following example? Example: if (( "$x"="1" && "$y"="a" && "$z"="happy" )) then do nothing else command command fi... (3 Replies)
Discussion started by: april
3 Replies
Login or Register to Ask a Question