If condition not working

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
# 1  
If condition not working

Hi Gurus,

I have shell script in which i have to check if time is between to possible value or not. For that i am using following line of code

if [ "$ftime" -gt 01:00 && "$ftime" -lt 05:00 ]
echo 'Found In Between'
echo $ftime
but when i am executing the script i am getting
test: ] missing

Please help me to resolve this.

Thanks in Advance
# 2  
Hammer & Screwdriver helo

if [ "$ftime" -gt 01:00 -a "$ftime" -lt 05:00 ]
echo 'Found In Between'
echo $ftime

You can use -a instead of &&
# 3  
I think -gt, -lt, etc... are for integers and not for dates. At least in my AIX, where "man test" shows:
Integer1 -eq Integer2 Returns a True exit value if the Integer1 and Integer2
variables are algebraically equal. Any of the comparisons -ne, -gt, -ge, -lt,
and -le can be used in place of -eq.

# 4  
i do agree with u gril ,thanks for calrification

manish if u wish u can try with this

cut minutes and hours in two variables

hr=`time | cut -c 1-2`
mn=`date | cut -c 3-4`

then compare separately according to ur requirement
if [ hr -gt ?? -a hr -lt ?? ]
# 5  
Originally Posted by NIMISH AGARWAL
manish if u wish u can try with this

cut minutes and hours in two variables

hr=`time | cut -c 1-2`
mn=`date | cut -c 3-4`

then compare separately according to ur requirement
if [ hr -gt ?? -a hr -lt ?? ]
Or (my pref) use ...

hr=`date +'%H'` (24hr format) //or// hr=`date +'%I'` (12hr format)
mn=`date +'%M'`
# 6  
May be this will help you

Hope the following will help you.

if [[ "$ftime" > "01:00"&&"$ftime" < "05:00" ]]; then
echo "$ftime"
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #950
Difficulty: Medium
The first academic work on the theory of self-replicating computer programs was done in 1949 by Alan Turing.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If condition on shell not working , not sure what is the mistake I am doing?

I have a requirement to perform specific set of tasks based on server , So I want to have the condition(s) defined based on server. Here is the script I came up with and I have read multiple blogs and couldn`t find any mistake from my script. Can you guide on what I am overlooking here ? ... (2 Replies)
Discussion started by: Varja
2 Replies

2. Shell Programming and Scripting

Disk Space Utilization in HTML format working in one environment and not working on the other

Hi Team, I have written the shell script which returns the result of the disk space filesystems which has crossed the threshold limit in HTML Format. Below mentioned is the script which worked perfectly on QA system. df -h | awk -v host=`hostname` ' BEGIN { print "<table border="4"... (13 Replies)
Discussion started by: Harihsun
13 Replies

3. UNIX for Beginners Questions & Answers

If condition is not working and getting error

Hi Team, If condition is not working properly and getting below error # ./score1.sh Enter your score ('q' for quit): 102 Enter your score ('q' for quit): q ./score1.sh: line 9: q: integer expression expected Average is: 102%. Exit. Actual code # Calculate the average of given... (3 Replies)
Discussion started by: Torrid
3 Replies

4. Shell Programming and Scripting

Automating pbrun /bin/su not working, whenever manually it is working using putty

I am trying to automate a script where I need to use pbrun /bin/su but for some reason it is not passing thru the pbrun as my code below. . ~/.bash_profile pbrun /bin/su - content c h 1 hpsvn up file path I am executing this from an external .sh file that is pointing to this scripts file... (14 Replies)
Discussion started by: jorgejac
14 Replies

5. Shell Programming and Scripting

If condition return 0 even when it fails to satisfy te condition

HI My doubt may be basic one but I need to get it clarified.. When i use "if" condition that checks for many AND, OR logical conditions like if ]; then return 0 fi Even the if condition fails it returns as zero.. Any clue.. But if i add else condition like if ]; ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

6. Shell Programming and Scripting

redirect stdout echo command in condition A run in condition B

hi, I have some problems in my simple script about the redirect echo stdout command inside a condition. Why is the echo command inside the elif still execute in the else command Here are my simple script After check on the two diff output the echo stdout redirect is present in two diff... (3 Replies)
Discussion started by: jao_madn
3 Replies

7. HP-UX

Difference between [condition] and [[condition]] and ((condition)) when used with if condition

Executed the following if conditions .. and got different results . only (( )) gave correct o/p with all scenarios . Can anybody please let me know what is the difference between and ] and ((condition)) when used with if condition. And why each condition gave different result. 1.... (2 Replies)
Discussion started by: soumyabubun
2 Replies

8. Shell Programming and Scripting

Using ssh to transfer file not working inside if-condition

Hi all, ssh uname@remote_server 'cat /tmp/remote_file_name > home_dir/a512386/new/local_file_name' The above given command is working fine. but if i try to move the file only if exists in the remote server i.e) giving the same within if condition it executes but the file is not stored in my... (1 Reply)
Discussion started by: Shri123
1 Replies

9. UNIX for Advanced & Expert Users

If condition and htm not working

Discussion started by: madfox
2 Replies

10. Shell Programming and Scripting

wild card in if condition not working

Hi, I am using RHEL5. I have following if condition. if In the above condition, if the value of a contains word WARNING, it should match. i.e., WARNING_MESSAGE, CRITICAL WARNING, WARNING ALERT etc. it should match. For b, alert error, ALERT ERROR, ERROR IMMEDIATE ACTION REQUIRED, etc... (2 Replies)
Discussion started by: user7509
2 Replies

Featured Tech Videos