|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
how to parse the command line argument to look for '@' sign and the following with '.'.
In my shell script one of the argument passed is email address. I want to parse this email address to look for correct format. rmjoe123@hotmail.com has '@' sign and followed by a '.' to be more specific : >abc.sh rmjoe123@hotmail.com abc.sh should parse this email address and look for '@' and then '.'. If email address is valid, abc.sh should continue doing what it is doing. Otherwise abort with error message. Last edited by M.Hirsch : July 29th, 2005 at 04:01 AM. Reason: thread opened so people can reply |
|
#2
|
|||
|
|||
|
Quote:
Try this: : [ $# -eq 1 ] || { echo "$0: call: $0 mail_address" >&2 exit 1 } case $1 in *@*.*) echo OK ;; *) echo ERROR exit 2 esac # Continue Regards ![]() |
|
#3
|
|||
|
|||
|
not this way
Quote:
a) the beginng test is needless, case catch the error b) the case has syntax errors and is c) too simple, matching every string containing at least a @ followed by a dot, so @@@@@....@@@@ @. ....@@@. are valid strings (( |
|
#4
|
|||
|
|||
|
Quote:
Well, yes, iribach, unfortunately you are right. But what you suggest? I do not see your solution. Next time I will be brave and shall test my scripts better. The next script was tested under ksh on AIX, Solaris and Linux: #!/usr/bin/ksh [ $# -eq 1 ] || { echo "$0: call: $0 email_address" exit 1 } case $1 in +([a-zA-Z0-9])@+([a-zA-Z0-9]).+([a-zA-Z0-9])) echo "OK: $1" ;; *) echo "NOT OK: $1" exit 2 ;; esac # Continue processing I have left the test of number of arguments on the beginning, it is right to give some advice to the user who has forgotten how to call the script. This kind of test is almost standard in shell scripting, I think. If I would test it under "case", I had to check for null string in $1 and according to the result to chose the appropriate error message. So I had to write some additional lines anyway. Have a fun ![]() |
|
#5
|
|||
|
|||
|
Quote:
yes iribach is ok the test at begin is really needless my comments: - i would not assume ksh is installed - rule1: there is ONLY ONE @ - rule2: a DOT cannot precede|follow ITSELF - rule3: a DOT cannot precede|follow a @ - rule4: a DOT must follow an other char - rule5: an other char must follow a DOT - this is not ok +([a-zA-Z0-9])@+([a-zA-Z0-9]).+([a-zA-Z0-9]) there are a lot other allowed chars just check that, OK i admit a C-pointer will do it in a better way then regexp
__________________
working on Solaris[5-9], preferred languages french and C. |
|
#6
|
|||
|
|||
|
Quote:
Sorry guggach, you are beating around the bush again. My second version of parsing meets all your rules. Why do you not try it on the computer? I have the feeling, you are posting steadily such ill-founded criticisms only to get a bigger number of posts only. Why do you never present YOUR ORIGINAL solution? Have you ever written a shell script? Show me (said Elisa Doolitle)! I have allowed myself to supppose the Korn shell is installed. If not, there are another tools, i. e. awk. It is quicker to develop than a C program using regexp, but I agree - it would be most professional. An experienced awk programmer would write such a parsing in two minutes time and a C program would need - say - half an hour to develop. The economy of machine time today is not as important today, you can save miliseconds only. The price of a programmer time plays the decisive role. Next time read what you write! Regards zlutovsky |
|
#7
|
|||
|
|||
|
Quote:
beatiful and ...... if you want teach me shell note [A-z0-9] and [A-Za-z0-9] are the same, just regexp understanding 2) prouve your shell is working i know adresses like: q-abc_=-9?>iuyiuyi@iuyiuy.080&^%%$# |
|
#8
|
||||
|
||||
|
Quote:
not true! do 'man ascii' and see what's between 'Z' and 'a'. Quote:
what does that mean? |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > shell script argument parsing |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|