You are right! Loginname doesn't look so complex. I just took a little practice.
I have a question: what if I want the loginname to start with an underscore or an alphabet and not to contain any spaces? What should I do?
Write down your exact set of requirements as a list of tests that need to be performed. You have the first two done:
Is the 1st character is _ or alpha class?
Are there any spaces? Although I imagine you might want: Are there any characters in class space (rather than just space characters to exclude tabs, newlines, vertical tabs, etc. in addition to the space character itself).
Do you have any other requirements about what characters are allowed or forbidden, minimum or maximum length restrictions, etc?
With your list of requirements and the code I supplied as a sample, try creating your own script. If it doesn't work, show us the complete set of requirements and show us what you tried. Then we'll try to help you fix the script to meet your requirements.
As you get more experience programming, you'll quickly learn it is MUCH easier to write a program if you write a complete set of requirements first.
PS Note that the script I provided doesn't allow any space characters in the login name.
Last edited by Don Cragun; 06-12-2013 at 02:36 PM..
Reason: Add PS.
Write down your exact set of requirements as a list of tests that need to be performed. You have the first two done:
Is the 1st character is _ or alpha class?
Are there any spaces? Although I imagine you might want: Are there any characters in class space (rather than just space characters to exclude tabs, newlines, vertical tabs, etc. in addition to the space character itself).
Do you have any other requirements about what characters are allowed or forbidden, minimum or maximum length restrictions, etc?
With your list of requirements and the code I supplied as a sample, try creating your own script. If it doesn't work, show us the complete set of requirements and show us what you tried. Then we'll try to help you fix the script to meet your requirements.
As you get more experience programming, you'll quickly learn it is MUCH easier to write a program if you write a complete set of requirements first.
PS Note that the script I provided doesn't allow any space characters in the login name.
OK!
My requirement is below:
1. the first and last character must be an underscore or an alphabet;
2. the length of the loginname should be between 8 and 16 characters long;
3. Except for first and last character, the digit or alphabet or 4 kinds of punctuation ( @ . - _ ) is only allowable.
OK!
My requirement is below:
1. the first and last character must be an underscore or an alphabet;
2. the length of the loginname should be between 8 and 16 characters long;
3. Except for first and last character, the digit or alphabet or 4 kinds of punctuation ( @ . - _ ) is only allowable.
You are off to a great start.
I repeat:
Quote:
With your list of requirements and the code I supplied as a sample, try creating your own script. If it doesn't work, show us the complete set of requirements and show us what you tried. Then we'll try to help you fix the script to meet your requirements.
I think I did it.
What confused me just now was why I couldn't replace [a-Z0-9_@.-] with [\w@.-].
---------- Post updated at 03:59 PM ---------- Previous update was at 03:27 PM ----------
Quote:
Originally Posted by Corona688
You can avoid printing the first time.
The && is a short-form if/then. If the first command succeeds, the second command will be executed.
I have another question:Why did I get an error with the first code? And it worked well with the second code first code: Error:
Quote:
./loginname_validate1: line 11: syntax error near unexpected token `elif'
./loginname_validate1: line 11: ` elif [ -z "${loginname}" ] && echo "You should enter a nonempty loginname." && return 1'
I think I did it.
What confused me just now was why I couldn't replace [a-Z0-9_@.-] with [\w@.-].
According to the standards, \w in a bracket expression in a Basic Regular Expression (as used by grep when the -E and -F options are not active) matches the two characters \ and w.
What I found surprising is that I hadn't seen anything indicating that the login names you wanted to verify were:
stored in a file,
that your wanted to include the line number in the file where they were stored as part of your list of valid names,
nor that the only character you wanted for the first and last character was "_".
Note that the a-Z in a range expression is treated as an empty set or as an error on most systems I've seen because "a" comes after "Z" in collating order in the C/POSIX locale. Looking more closely at the standards, it is ambiguous as to whether a backwards range should be accepted. If it is accepted it would contain the characters Z, [, \, ], ^, _, `, and a; not lowercase and uppercase letters.
Quote:
Originally Posted by franksunnn
---------- Post updated at 03:59 PM ---------- Previous update was at 03:27 PM ----------
I have another question:Why did I get an error with the first code? And it worked well with the second code first code: Error:
second code:
You also did not mention that your code checking valid login names was going to be included in a function. But, the return statement is only vaiid inside a function.
Whether it is in a function or not, there are two ways to code the equivalent of an if statement (ignoring elif clauses):
which matches what you have shown above as second code, and equivalently
What you are showing above as first code is a cross between the two that is a syntax error; the if keyword requires matching then and fi keywords.
I had expected that you were going to try to pattern your updated code based on the code I had supplied earlier. I thought it was working for you, but you had changed the requirements concerning what was to be considered a valid login name.
What you have here is a completely different concept. And, with the short snippets of code you have shown, I no longer have any idea what you're trying to do.
This User Gave Thanks to Don Cragun For This Post:
I need help. I am trying to get this script to send out only one email not multiple emails of the abend. Currently it will send me one then and ther with the first and second one then another email with the first second and third abend and so on. I only want one email sent.
... (2 Replies)
Hi i just want to open 2 files and find difference between cond1 and cond2 and if the difference is greater than or equal to some number say 2 print the lines again in 2 different files.
file 1 (1.txt)
aqw dfr 34
poilo ggg 98
file 2 (2.txt)
qww asd 28
poilo ggg 97 open FILE1,"1.txt" or... (2 Replies)
I have been trying to come up with a program that can do this:
Say I have a file named "sir" with a single field;
10
229
288
35
83
47
3
I want to create a file "gen" with three fields with the data in file "sire" listed in field 1 while field 2 and 3 are just 1 each like this:
SPARSE... (1 Reply)
Hi friends,
I'm newbie to SVM.
Just wanna try installed it on one of our server (to do mirroring for disk0 and disk1) but i think im lost until now. :(
the steps i've taken is as below:-
1.prtvtoc /dev/rdsk/c1t0d0s2 | fmthard -s - /dev/rdsk/c1t1d0s2
2.metadb -a -c 3 -f c1t0d0s7... (3 Replies)
Hi all,
I have a directory which has many sub-directories. Now, I want to check the space of each dir and redirect the output in a file if space exceeds the limit.
I have already done it, but the way I did is not very good. I just listed the directories and awked the last column to get the... (5 Replies)
I run into a issue when I try to do sorting of the following with ascending order, one round of for looping seems not working, anyone knows how to use shell or perl?
$array = (5,0,3,2,7,9,8) (2 Replies)
Hi all
I have tried to search for this, but keep getting a MySQL db connect error, so am posing the question here, and taking a risk of incurring the wrath of the mods with my first post...
I have the following test script:
#!/bin/bash
HTTPD=`/bin/ps -axcu | /usr/bin/grep httpd... (6 Replies)
I am having a problem with awk when I run it with a loop. It works perfectly when I echo a single line from the commandline. For example:
echo 'MFG009 9153852832' | awk '$2 ~ /^0-9]$/{print $2}'
The Awk command above will print field 2 if field 2 matches 10 digits, but when I run the loop... (5 Replies)
Hi,
Actually I have a file which consists data . for eg names.
Then I want my sql query to read this file and produce the output.
Currently I am using this
FOR EG : FILENAME is NAMES
for i in `cat NAMES`
{
sqlplus -s $CONNECTID << EOF
spool rooh
set heading off
select... (1 Reply)