- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- IF statement construct
Operating System - Linux
1755759
Members
2855
Online
108838
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-16-2007 02:47 AM
тАО05-16-2007 02:47 AM
I'm currently looking to edit a if statement within script.
The current syntax is
if [[ $(date +%H) -gt 8 ]]
so if it is after 08:00 the next statement runs. I want the if statement to say that if its -gt 8 and -lt 21 , how would I oncorporate that ??
Cheers,
Berd
The current syntax is
if [[ $(date +%H) -gt 8 ]]
so if it is after 08:00 the next statement runs. I want the if statement to say that if its -gt 8 and -lt 21 , how would I oncorporate that ??
Cheers,
Berd
Solved! Go to Solution.
- Tags:
- date
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-16-2007 02:54 AM
тАО05-16-2007 02:54 AM
Solution
Your problem is both a syntactical one and a logical one. First, it is possible that the very thing you are testing (time) could change while doing the test so it's wiser to capture it in a variable and then test the variable.
CURRHR=$(date '+%H')
if [[ ${CURRHR} -gt 8 && ${CURRHR} -lt 21 ]]
then
fi
--- or to use the external test command
if [ ${CURRHR} -gt 8 -a ${CURRHR} -lt 21 ]
then
fi
CURRHR=$(date '+%H')
if [[ ${CURRHR} -gt 8 && ${CURRHR} -lt 21 ]]
then
fi
--- or to use the external test command
if [ ${CURRHR} -gt 8 -a ${CURRHR} -lt 21 ]
then
fi
If it ain't broke, I can fix that.
- Tags:
- Test
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-16-2007 02:55 AM
тАО05-16-2007 02:55 AM
Re: IF statement construct
Hi Berd:
# if [[ $(date +%H) -gt 8 && $(date +%H) -lt 21 ]]
...although it would be better to first capture the hour in a variable to avoid the repetitive call:
# H=$(date +%H)
# if [[ "${H}" -gt 8 && "${H}" -lt 11 ]]
Regards!
...JRF...
# if [[ $(date +%H) -gt 8 && $(date +%H) -lt 21 ]]
...although it would be better to first capture the hour in a variable to avoid the repetitive call:
# H=$(date +%H)
# if [[ "${H}" -gt 8 && "${H}" -lt 11 ]]
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-16-2007 03:07 AM
тАО05-16-2007 03:07 AM
Re: IF statement construct
Cheers guys for that, I will amend script as suggested.
Berd
Berd
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP