Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
no no i understand, its just it becomes confusing with variables, I mean I'm trying to figure out how to cut the time and make the loop work, its good I dont have answers, but somehow I will find them... :S
Your reading in two variables, hour and minute but then you want to
use the cut command to split time. Most commands require the - (hyphen)
for specifying options. The correct syntax for the cut command would be
cut -d ":" -f1
and here is a hint for cut:
echo "12:59" | cut -d ":" -f1
I agree with BW-userx. If you break down the assignment into smaller parts it will seem less complicated. Ignore the if [hour=end] for now and work on the hour and minute variables working.
#!/bin/bash
#
#
#
sortie="false"
while [ $sortie = "false" ]
do
read -p "temps : " temps
heure=$(echo "$temps" | cut -d: -f1)
minute=$(echo "$temps" | cut -d: -f2)
if [ "$temps" = "fin" ]
then
sortie="true"
# let sortie="true"
else
if [[ "$heure" -ge "00" ]] && [[ "$heure" -lt "24" ]] && [[ "$minute" -ge "00" ]] && [[ "$minute" -le "60" ]]
then
if [[ "$heure" -gt "5" ]] && [[ "$heure" -lt "19" ]]
then
printf "%s\nBonjour\n"
else
printf "%s\nBonsoir\n"
fi
else
printf "%s\nHeure incorrecte\n"
fi
fi
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.