Sponsored Content
Full Discussion: if, else help!
Top Forums Shell Programming and Scripting if, else help! Post 302291892 by cfajohnson on Thursday 26th of February 2009 02:04:57 PM
Old 02-26-2009
Quote:
Originally Posted by mehrdad68
Hi,
I've got the following script:
Code:
YEAR=`date '+%Y'`
MONTH=`date '+%m'`
DAY=`date '+%d'`
HOUR=`date '+%H'`
MINUTE=`date '+%M'`


Not only are multiple calls to date unnecessary (and slow), but the script will fail if the time passes a boundary between calls.

Use a single call to date:

Code:
eval "$( date '+ YEAR=%Y MONTH=%m DAY=%d HOUR=%H MINUTE=%M' )"

Quote:
Code:
LASTHOUR=$((HOUR-1))

Code:
LASTHOUR=$(( ${HOUR#0} - 1 ))

Quote:
What i like to do is:

Code:
if $LASTHOUR < 9 then
function1
else 
function2

Code:
if [ ${LASTHOUR#0} -lt 9 ]
then
  function1
else
  function2
fi

 
MESSAGES(3)						  libbash messages Library Manual					       MESSAGES(3)

NAME
messages -- libbash library that implements a set of functions to print standard status messages SYNOPSIS
printOK [indent] printFAIL [indent] printNA [indent] printATTN [indent] printWAIT [indent] DESCRIPTION
General messages is a collection of functions to print standard status messages - those [ OK ] and [FAIL] messages you see during Linux boot process. The function list: printOK Prints a standard [ OK ] message (green) printFAIL Prints a standard [FAIL] message (red) printNA Prints a standard [ N/A] message (yellow) printATTN Prints a standard [ATTN] message (yellow) printWAIT Prints a standard [WAIT] message (yellow) Detailed interface description follows. indent Column to move to before printing. Default indent is calculated as TTY_WIDTH-10. If current tty width can not be determined (for example, in case of serial console), it defaults to 80, so default indent is 80-10=10 FUNCTIONS DESCRIPTIONS
printOK [indent] Prints a standard [ OK ] message (green) printFAIL [indent] Prints a standard [FAIL] message (red) printNA [indent] Prints a standard [ N/A] message (yellow) printATTN [indent] Prints a standard [ATTN] message (yellow) printWAIT [indent] Prints a standard [WAIT] message (yellow) EXAMPLES
Run a program named MyProg, and report it's success or failure: echo -n 'Running MyProg...' printWAIT if MyProg ; then printOK else printFAIL fi AUTHORS
Hai Zaar <haizaar@haizaar.com> Gil Ran <gil@ran4.net> SEE ALSO
ldbash(1), libbash(1) Linux Epoch Linux
All times are GMT -4. The time now is 11:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy