Testing for strings, and numbers
aart at mtack.xs4all.nl
Fri Nov 13 13:50:31 UTC 2009
On Fri, 13 Nov 2009 05:24:13 -0800, Ray Parrish wrote:
> 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.
> All of my attempts so far have been stymied, and I can't seem to find
> the excellent bash reference I had been using before, and am trying to
> navigate a couple of less than excellent references that do not include
> sections on string handling.
> Could someone help me with this please?
> Thanks, Ray Parrish
I think you could use sed for that, testing with ^http or ^[0-9]. To only
look at the first line you can use sed '1 q'. ^ means look if the line
start with the expression. sed can easely be integrated in a bash script,
but how you have to do it depends on your needs. It all can be done with
perl too, some will find that more convienent
More information about the ubuntu-users