FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu User

 
 
LinkBack Thread Tools
 
Old 11-13-2009, 12:24 PM
Ray Parrish
 
Default Testing for strings, and numbers

Hello,

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

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



--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 11-13-2009, 12:50 PM
Aart Koelewijn
 
Default Testing for strings, and numbers

On Fri, 13 Nov 2009 05:24:13 -0800, Ray Parrish wrote:

> Hello,
>
> 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

Aart


--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 11-13-2009, 01:14 PM
Nils Kassube
 
Default Testing for strings, and numbers

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.

echo "$1"|grep -q '^http://' && echo yes || echo no

> Also I would like to know how to test $1 to see if it begins with a
> numeric digit.

echo "$1"|grep -q '^[0-9]' && echo yes || echo no

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

You can of course do it with bash string operations but I think grep is
simpler here. I don't know which bash reference you mean but I prefer
"learning the bash shell" by Cameron Newham & Bill Rosenblatt (O'Reilley
book).


Nils

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 11-13-2009, 01:20 PM
Chris G
 
Default Testing for strings, and numbers

On Fri, Nov 13, 2009 at 03:14:36PM +0100, Nils Kassube wrote:
> 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.
>
> echo "$1"|grep -q '^http://' && echo yes || echo no
>
> > Also I would like to know how to test $1 to see if it begins with a
> > numeric digit.
>
> echo "$1"|grep -q '^[0-9]' && echo yes || echo no
>
> > 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.
>
> You can of course do it with bash string operations but I think grep is
> simpler here. I don't know which bash reference you mean but I prefer
> "learning the bash shell" by Cameron Newham & Bill Rosenblatt (O'Reilley
> book).
>
If you have python installed then I'd advise using that, *much* easier
than bash (or other shells) for string operations like this. I use
python for just about everything except really trivial little scripts.

--
Chris Green


--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 11-13-2009, 02:01 PM
Florian Diesch
 
Default Testing for strings, and numbers

Ray Parrish <crp@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
--
<http://www.florian-diesch.de/linux/asciipinguine.html>

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 11-13-2009, 04:02 PM
Ray Parrish
 
Default Testing for strings, and numbers

Florian Diesch wrote:
> Ray Parrish <crp@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



--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 

Thread Tools




All times are GMT. The time now is 11:32 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org