LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-04-2011, 07:03 AM   #1
itstudent
LQ Newbie
 
Registered: Nov 2011
Posts: 2

Rep: Reputation: Disabled
Question reglar expression ,help


HI ...
I have to write shell script programing that allow root user to add user or more to the system , I could write the most of script Requirements , but i find it difficult to do this :
the root can add and enter the home directory for each user but my problem is :

Ask the user to provide the following data:
Home directory:
Default is /home/<login>
The script accepts either /home/<string> or /<string>. <string> must
not exceed 10 alphanumeric characters


i find result using regular expression , file globbing ,but i could not find the perfect way and the answer to do that
can you please help me or give me name of good reference ?
 
Old 11-04-2011, 07:16 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
If the shell you are using supports the =~ comparison operator then the regex on the right conforms to the description in the regex 7 man page, accessible using
Code:
man 7 regex
Alternatively you could use bash file name expansion pattern matching in a case statement.
 
0 members found this post helpful.
Old 11-04-2011, 07:33 AM   #3
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
I would use basename (if available) to extract the home dir name, then complete the path in the script
 
Old 11-04-2011, 12:01 PM   #4
itstudent
LQ Newbie
 
Registered: Nov 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks so much
but my question is how to allow user to add

string consist of alphabet or numeric characters only
and string length not exceed 10 alphanumeric characters.
I use bash script

Last edited by itstudent; 11-04-2011 at 01:44 PM.
 
Old 11-04-2011, 01:47 PM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by itstudent View Post
Thanks so much
but my question is how to allow user to add

string consist of alphabet or numeric characters only
and string length not exceed 10 alphanumeric characters.
So you write the script to ask the user to input the home directory and then validate it:
  1. Strip any /home from the left
  2. Check that what remains matches a regular expression that is / followed by "up to 10" (presumably 1 to 10) alphanumeric characters
LQ does not do homework questions for people. It gives hints about how to answer the question and, when you show what you have tried that didn't work, gives more help.
 
  


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
Regular expression help smeezekitty Programming 7 03-27-2011 07:57 PM
Regular Expression lewkh Linux - General 3 04-30-2010 03:01 AM
problem with expression hchoonbeng Linux - Newbie 3 10-09-2008 04:09 AM
regular expression Ammad Linux - General 5 08-01-2008 07:41 AM
Regular Expression msvinaykumar Programming 2 08-14-2006 08:48 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:04 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