LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 09-16-2022, 10:44 AM   #1
nour_
LQ Newbie
 
Registered: Sep 2022
Posts: 4

Rep: Reputation: 0
Question -lt and -le in while loop conditions


Hello everyone,
I'm new to bash scripting and i was looking at while loop examples that have the following in the condition:
while [ $x -le 5 ]
while [ $count -lt 5 ]

what does -le and -lt mean?
 
Old 09-16-2022, 11:10 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
[ is a synonym for test, so try this at the command line:
Code:
help test
 
Old 09-16-2022, 11:41 AM   #3
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,818

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by nour_ View Post
Hello everyone,
I'm new to bash scripting and i was looking at while loop examples that have the following in the condition:
while [ $x -le 5 ]
while [ $count -lt 5 ]

what does -le and -lt mean?
A part of the script (above the while loop) is setting "x" to some value that needs to be less than--or less than or equal to--the value 5. Or... some activity within the "body" of the while loop may be redefining "x". The script will stay in the loop until the test fails. I.e.:
Code:
#!/bin/bash
x=0
while [ $x -le 5 ]
do
     echo -e "Enter a number: \c"; read x 
     echo $x
done
echo "We exited the loop"
(OK. Dumb example but you get the idea.)

Issue "man test" and read that page for an explanation of those two tests---the explanations are pretty clear.

HTH...
 
  


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
[SOLVED] if loop with multiple conditions cnitin Linux - Newbie 5 12-09-2012 11:42 PM
multiple conditions in while() loop in C glosterj9 Programming 1 12-27-2011 11:16 AM
[SOLVED] Bash - While Loop reading from two lists simultaneously - nested while loop wolverene13 Programming 11 10-01-2011 05:00 PM
Bash while loop with 2 conditions. elinenbe Programming 2 10-14-2007 12:06 AM
shell script - while loop with multiple conditions ronsha Programming 13 12-10-2005 04:08 PM

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

All times are GMT -5. The time now is 07:07 AM.

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