Results 1 to 2 of 2
First of all i just want to say that I'm quite new to bash scripting.
So, I'm trying to make a script to tell if it is day or night. ...
- 02-21-2011 #1Just Joined!
- Join Date
- Sep 2010
- Posts
- 9
Day or night script?
First of all i just want to say that I'm quite new to bash scripting.
So, I'm trying to make a script to tell if it is day or night. The purpose of the script is to execute an action if it is day and a different one if it is night when the script is executed.
So far i have this:
The problem here is that, when the clock is 21 (yes, I use a 24 hour clock), the script tells me it's both day and night. So how can i fix this to display only one of the options?Code:#!/bin/bash typeset -i TIME typeset -i DAY typeset -i NIGHT TIME=$(date +"%H") DAY='10' NIGHT='20' if [ ${TIME} -gt ${DAY} ]; then echo "It's day!" else exit fi if [ ${TIME} -gt ${NIGHT} ]; then echo "It's night!" else exit fi
The echoes are only there for testing purposes.
- 02-22-2011 #2Just Joined!
- Join Date
- Feb 2011
- Posts
- 2
Assuming that you want it to return "Day" between 10:00 and 20:59, and return "Night" between 21:00 and 09:59, you might want to try this:
Code:#!/bin/bash TIME=$(date +"%H") DAY='10' NIGHT='20' if [ ${TIME} -ge ${DAY} -a ${TIME} -le ${NIGHT} ]; then echo "It's day!" else echo "It's night!" fi


Reply With Quote