LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 02-24-2016, 08:16 AM   #16
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,680

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894

True, however we do not want to introduce commands that the OP has not learned yet so as not to add to the confusion nor just write the program.
 
Old 02-24-2016, 03:25 PM   #17
kernkraftx
LQ Newbie
 
Registered: Feb 2016
Location: Canada
Distribution: Suse Mint
Posts: 19

Original Poster
Rep: Reputation: Disabled
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
 
Old 02-24-2016, 03:36 PM   #18
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Advice using cut & echo combination commands



Code:
	#Capitalizes each word
pref="$(echo -e "${pref}" | sed -r 's/([\b ]?)(.)([a-zA-Z]*)/\1\U\2\L\3/')"
good link for loops


do you have to use cut to get the data you need?

plus d'une façon à la peau d'un chat

use these google key words for working with string data which is what you are doing

"string manipulation bash linux"

Last edited by BW-userx; 02-24-2016 at 03:51 PM.
 
Old 02-24-2016, 03:46 PM   #19
kernkraftx
LQ Newbie
 
Registered: Feb 2016
Location: Canada
Distribution: Suse Mint
Posts: 19

Original Poster
Rep: Reputation: Disabled
#!/bin/bash


while [ sortie="true" ]
do

echo -n "Entrez l'heure sous forme hh:mm ou fin terminer :"

read temps

heure= "$temps" |cut -d: f1
minute= "$temps" |cut -d: f2

if [ $heure = "fin" ]

then
let sortie = "false"

fi

if [[ "$heure" -ge 0 ]] && [[ "$heure" -le 23 ]] && [[ "$minute" -ge 0 ]] && [[ "$minute" -le 59 ]]
then
if [[ "$heure" -ge 6 ]] && [[ "$heure" -le 18 ]]
then
echo "Bonjour"

else

echo "Bonsoir"
fi


fi

sortie = "false"
done
 
Old 02-24-2016, 03:52 PM   #20
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,680

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
Looks like you are making some progress.

Did you look at my hint on the proper syntax for cut in my previous post #14? You can substitute $temps for "12:59".
 
Old 02-24-2016, 04:05 PM   #21
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Improper if statments

use echo to see what's going on in your code

ie:

Code:
read temps

echo "temps: $temps"

heure= "$temps" |cut -d: f1
minute= "$temps" |cut -d: f2

echo "Heure: $heure"
echo "minute: $minute"
review @michaelk hints

Code:
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

Last edited by BW-userx; 02-24-2016 at 04:29 PM.
 
Old 02-24-2016, 04:07 PM   #22
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by michaelk View Post
Looks like you are making some progress.

Did you look at my hint on the proper syntax for cut in my previous post #14? You can substitute $temps for "12:59".
hopefully you know the word temps means time in french

not trying to step on your toes, or a I miss interpreting your english? lol

Last edited by BW-userx; 02-24-2016 at 04:16 PM.
 
Old 02-24-2016, 05:04 PM   #23
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
pay attention to detail

prêter attention aux détails


Variable Assignment

learn your loop control very important!!!

faire preuve d'innovation

Last edited by BW-userx; 02-24-2016 at 05:28 PM.
 
Old 02-24-2016, 05:14 PM   #24
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,680

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
Nope.

Just trying to explain to the op that

echo "12:59" | cut -d ":" -f1

would become

echo "$temps" | cut -d ":" -f1

Now just assign that to the variable heure.
 
Old 02-24-2016, 05:16 PM   #25
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by michaelk View Post
Nope.

Just trying to explain to the op that

echo "12:59" | cut -d ":" -f1

would become

echo "$temps" | cut -d ":" -f1

Now just assign that to the variable heure.
yeah I got what you meant after I posted ... lol
 
Old 02-24-2016, 05:54 PM   #26
kernkraftx
LQ Newbie
 
Registered: Feb 2016
Location: Canada
Distribution: Suse Mint
Posts: 19

Original Poster
Rep: Reputation: Disabled
thanks anyways, why does this seem complicated... well back to study on this hopeless assignment
 
Old 02-24-2016, 05:59 PM   #27
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
you're NOT paying attention to detail?

"If you begin with the notion that something is impossible, then it obviously will be for you." - Unknown

Last edited by BW-userx; 02-24-2016 at 06:09 PM.
 
Old 02-24-2016, 06:35 PM   #28
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,680

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
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.
 
Old 02-26-2016, 11:56 AM   #29
kernkraftx
LQ Newbie
 
Registered: Feb 2016
Location: Canada
Distribution: Suse Mint
Posts: 19

Original Poster
Rep: Reputation: Disabled
#!/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

done
echo

here no more bashing me please.
 
Old 02-26-2016, 01:00 PM   #30
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Apparently your English is poor ... let us try this:

Vous devez utiliser des balises de code lors de l'affichage de votre script
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
College Homework Help, Statistics Homework Help, Finance Homework Help, Accounting markstephen Linux - Software 1 11-14-2009 03:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration