Testing for strings, and numbers

Ray Parrish crp at cmc.net
Fri Nov 13 17:02:53 UTC 2009


Florian Diesch wrote:
> Ray Parrish <crp at cmc.net> writes:
>
>   
>> I am writing a bash script and I would like to test $1 to see if it 
>> begins with the string "http://" but I am not coming up with a method of 
>> doing so.
>>
>> Also I would like to know how to test $1 to see if it begins with a 
>> numeric digit.
>>     
>
>
> case "$1" in
>     http://*) echo http;;
>     [0-9]*) echo Numeric;;
>     *) echo Unknown;;
> esac
>
>
>
>    Florian
>   
Hello,

This case statement syntax was exactly what I was looking for, and it is 
working for me in my script now. I'm using it to validate command line 
parameters for my Web Site Monitor script.

Thank you, and thank all of the others who answered with good solutions 
as well.

Web Site Monitor is getting a facelift, with Xdialog now providing a Web 
Site Monitor GUI ran from a wrapper script for PollWebSite.sh called 
GUIPollWebSite.sh

Look for the new version within days on Ray's Links.

Later, Ray Parrish

-- 
The Future of Technology.
http://www.rayslinks.com/The%20Future%20of%20Technology.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com






More information about the ubuntu-users mailing list