UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 28th, 2005, 02:37 PM
rmjoe rmjoe is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 1 rmjoe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 25 sec
Reputation Power: 0
Question shell script argument parsing

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

Reply With Quote
  #2  
Old July 29th, 2005, 07:22 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 117 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 42 m 44 sec
Reputation Power: 6
Quote:
Originally Posted by rmjoe
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.



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

Reply With Quote
  #3  
Old July 30th, 2005, 09:43 AM
iribach iribach is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 23 iribach User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 31 m 47 sec
Reputation Power: 0
not this way

Quote:
Originally Posted by zlutovsky
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


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 ((

Reply With Quote
  #4  
Old August 3rd, 2005, 08:53 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 117 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 42 m 44 sec
Reputation Power: 6
Quote:
Originally Posted by iribach
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 ((



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

Reply With Quote
  #5  
Old August 8th, 2005, 04:15 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,089 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 5 Days 3 h 43 m 40 sec
Reputation Power: 9
Quote:
Originally Posted by zlutovsky
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


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.

Reply With Quote
  #6  
Old August 8th, 2005, 07:51 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 117 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 42 m 44 sec
Reputation Power: 6
Quote:
Originally Posted by guggach
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


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

Reply With Quote
  #7  
Old August 10th, 2005, 07:35 PM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,089 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 5 Days 3 h 43 m 40 sec
Reputation Power: 9
Quote:
Originally Posted by zlutovsky
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

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&^%%$#

Reply With Quote
  #8  
Old August 11th, 2005, 05:38 PM
vgersh99 vgersh99 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 47 vgersh99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 Days 5 h 41 m 53 sec
Reputation Power: 4
Send a message via AIM to vgersh99 Send a message via MSN to vgersh99 Send a message via Yahoo to vgersh99
Quote:
Originally Posted by guggach
beatiful and ......
if you want teach me shell note
[A-z0-9] and [A-Za-z0-9] are the same, just regexp understanding


not true! do 'man ascii' and see what's between 'Z' and 'a'.

Quote:
Originally Posted by guggach
2) prouve your shell is working
i know adresses like: q-abc_=-9?>iuyiuyi@iuyiuy.080&^%%$#


what does that mean?

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > shell script argument parsing


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway