LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How do i compare characters (https://www.linuxquestions.org/questions/linux-newbie-8/how-do-i-compare-characters-4175436768/)

teorxv102 11-12-2012 08:40 AM

How do i compare characters
 
I have a question on how to compare numbers like passlength
my question is the password policy requires a minimum length of 6
heres the following code that i used

if grep '^PASSLENGTH=6' /etc/default/passwd
then
echo exception No
else
echo exception yes
fi

so what codes should i add so that it has PASSLENGTH =<6
Thanks in advance

colucix 11-12-2012 09:18 AM

Maybe this:
Code:

if grep -q '^PASSLENGTH=[0-6]$'
then
  ...

It matches a single digit between 0 and 6. The "end of line" anchor ($) ensures it doesn't match 10, 11 or any other number starting with a digit between 0 and 6. Hope this help and welcome to LinuxQuestions!

teorxv102 11-12-2012 07:33 PM

Tys that help alot

teorxv102 11-12-2012 07:46 PM

One last question if right after PASSLENGTH= if it is empty how should i write my code to make an exception

catkin 11-12-2012 09:19 PM

Quote:

Originally Posted by teorxv102 (Post 4827963)
One last question if right after PASSLENGTH= if it is empty how should i write my code to make an exception

That is answered in teorxv102's similar thread here.


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