[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

help with bash script



Hallo,

I am just starting to use small bash scripts on my system and I enjoy it.

I am using the following bash script to query my postgresql database using
"van" (surname) as search field:

time echo "select noemnaam,van,adres1,telefoon,werktelefoon,selfoon,faks
from lidmate,besoekpunt where lower(van) like lower('$1%') and bpnommer =
besoekpunt.nommer order by van, noemnaam;" | psql jhspies

I use it like this:

telef marais

When I want to narrow the search I use it in the following way:

telef marais | grep -i gert

supplying a name (gert) to look for.

I want to modify my script so that I can do either

telef marais 
or
telef marais gert

What I do not know is how to handle the possible second argument on the
command line.  The script must be able to use the second argument if there
is one otherwise it should use the query as it is at the moment.

I have looked at the bash man page, but could so far not find an answer.

Johann

 --------------------------------------------------------------------------
| Johann Spies                                 Windsorlaan 19              |
| jhspies@futurenet.co.za                3201 Pietermaritzburg             |
| Tel/Faks Nr. +27 331-46-1310		       Suid-Afrika (South Africa)  |
 --------------------------------------------------------------------------

     "He that giveth unto the poor shall not lack..."       
                         Proverbs 28:27 


Reply to: