LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 11-12-2012, 08:40 AM   #1
teorxv102
LQ Newbie
 
Registered: Nov 2012
Posts: 5

Rep: Reputation: Disabled
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
 
Old 11-12-2012, 09:18 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
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!
 
Old 11-12-2012, 07:33 PM   #3
teorxv102
LQ Newbie
 
Registered: Nov 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Tys that help alot
 
Old 11-12-2012, 07:46 PM   #4
teorxv102
LQ Newbie
 
Registered: Nov 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
One last question if right after PASSLENGTH= if it is empty how should i write my code to make an exception
 
Old 11-12-2012, 09:19 PM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by teorxv102 View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Bash compare characters action_owl Programming 3 03-04-2010 08:13 AM
LXer: Mastering Characters Sets in Linux (Weird Characters, part 2) LXer Syndicated Linux News 0 11-25-2009 11:30 PM
splitting numbers and characters from an array of characters. trscookie Programming 6 11-14-2008 09:34 AM
Compare first characters of a string in UNIX shell loopoo Linux - Newbie 8 12-11-2006 11:35 AM
How to modify the names of files and replace characters with other characters or symb peter88 Linux - General 2 12-10-2006 03:05 AM


All times are GMT -5. The time now is 05:07 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration