help


 
Thread Tools Search this Thread
Operating Systems Linux help
# 1  
Old 12-15-2005
Data help

ey.. i just started learning shell scripting in Mandrake linux... I have a program that will have to accept arguments and do validations if the arguments entered are containing characters other than numeric characters... I was able to detect alphabetic characters and symbols like , + - . etc.... and error messages are displayed. But when arguments containing symbols like * ) [ & ( and other characters which have special meanings, my script is not able to trap them and treat as ordinary strings that are part of my arguments...
to explain more clearly.. here's an example..

# ./sample.sh a677 7 678
--->>> here, a message indicating that the first argument contains a character is displayed. This one works correctly.

# ./sample.sh 344 56& 557
---->>> here's the prob... this time,,, it stops when it reaches the symbol & and displays a message from bash... If I use single ( or ), an error message from bash also displays.

Can anyone help me with this?
# 2  
Old 12-15-2005
You could always put quotes around your arguments e.g.

sample.sh "123" "1231&" "12"

To be absolutely sure 'escape' special characters:

sample.sh "123" 1231\&" "12"

If you are trying to pass asterisk through:

sample.sh "*"

or if you really mean to pass the result of *:

sample.sh ${*}


Hope this helps!
# 3  
Old 12-16-2005
Power

hi mbb.... thanks for the info.. I hope that is what they want me to do.... Smilie
I can't place escape characters or quotes to those special characters when I use them as part of my arguments. I have to find a way to display a message that will indicate that a special character is included in my arguments...

Do you or does anyone know how to do this? Or is there really a way that my script may treat them as an ordinary part of my string arguments? The only hint I got from them (those who are asking me to do this exercise) is that I have to trap the special character before the shell performs the character's function. Smilie(

This is too tough for me... hope I can hear some feedback.. thanks so much in advance..... Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question