LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-21-2011, 02:11 PM   #1
lipun4u
Member
 
Registered: Sep 2008
Location: Mumbai, india
Distribution: ubuntu and hp-unix
Posts: 118

Rep: Reputation: 15
please fix the bug


plz go throuugh the following code...

Code:
#!/bin/bash
set -x


if [ $# -ne 2 ]
then
        echo "Usage : $(basename) <start-date> <end-date>"
        exit 1
fi

start_date=$1
end_date=$2
process_name=$(basename $0)
log_file="${process_name}_$(date +%d%m%Y%H%M%S).LOG"

##$>>$log_file

date -d"+$k day" +%d%b%Y | tr [:lower:] [:upper:]

convert_to_days()
{
        local tot_sec
        local ip_date="$1"

        tot_sec=$(date -d "$ip_date" +%s)

        echo $(( $tot_sec / ( 24 * 3600) ))
}

compare_date_days()
{
        local start_dt
        local end_dt

        start_dt=$(convert_to_days "$1")
        end_dt="$(convert_to_days "$2")

        if [ $start_dt -gt $end_dt ]
        then
                echo "-1"
        elif [ $start_dt -lt $end_dt ]
        then
                echo "1"
        else
                echo "0"
        fi
}





echo "Start Date : $(convert_to_days $start_date )"
echo "End Date : $(convert_to_days $end_date )"

echo $(compare_date_days $start_date $end_date)
when i run, it says that there is a bug at line 54.
 
Old 02-21-2011, 02:48 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

At first glance: You call your functions as a separate process ($(convert_to_days $start_date )), no need for that.

Something like this is better (untested):
Code:
echo -n "Start Date : " convert_to_days $start_date
echo -n "End Date : " convert_to_days $end_date
You do this more then once in your script, modify all those lines.

Hope this helps.
 
Old 02-21-2011, 02:49 PM   #3
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Can you post the output of the script?

And FYI, please use something more descriptive in your subject line next time. Just using "please fix the bug" is telling me that you want someone else to do the work for you. We are here to assist, not to do everything for you. Thanks!
 
Old 02-21-2011, 02:49 PM   #4
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Try:

Code:
#!/bin/bash
set -x


if [ $# -ne 2 ]
then
        echo "Usage : $(basename) <start-date> <end-date>"
        exit 1
fi

start_date=$1
end_date=$2
process_name=$(basename $0)
log_file="${process_name}_$(date +%d%m%Y%H%M%S).LOG"

##$>>$log_file

date -d"+$k day" +%d%b%Y | tr [:lower:] [:upper:]

convert_to_days()
{
        local tot_sec
        local ip_date="$1"

        tot_sec=$(date -d "$ip_date" +%s)

        echo $(( $tot_sec / ( 24 * 3600) ))
}

compare_date_days()
{
        local start_dt
        local end_dt

        start_dt=$(convert_to_days "$1")
        end_dt=$(convert_to_days "$2")

        if [ $start_dt -gt $end_dt ]
        then
                echo "-1"
        elif [ $start_dt -lt $end_dt ]
        then
                echo "1"
        else
                echo "0"
        fi
}





echo "Start Date : $(convert_to_days $start_date )"
echo "End Date : $(convert_to_days $end_date )"

echo $(compare_date_days $start_date $end_date)
 
  


Reply

Tags
bash



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bug#314905 bug fix for Ubuntu and gcc is 4.4.1 bostan Linux - General 1 12-11-2010 12:35 PM
Non bug fix update to 13.1 samac Slackware 13 06-30-2010 04:05 PM
Terminal Bug/Fix mjolnir Solaris / OpenSolaris 0 03-02-2010 11:11 AM
Bug Fix Ctp. Obvious Linux - Newbie 5 08-02-2004 06:58 AM
Bug fix update for 10.0 akihandyman Mandriva 3 07-14-2004 04:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration