Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com X-Originating-IP: [212.120.146.244] From: "Nrusinh Ambekar" To: cygwin AT cygwin DOT com Subject: Re: problem - if statement in shell script gives opposite results with new bash Date: Wed, 02 Oct 2002 15:18:27 +0000 Mime-Version: 1.0 Content-Type: text/plain; format=flowed Message-ID: X-OriginalArrivalTime: 02 Oct 2002 15:18:28.0167 (UTC) FILETIME=[F59AF570:01C26A26] Hi Igor, Thanks very much for your help. After this change, its working fine. Regards, Nrusinh >From: Igor Pechtchanski >Reply-To: cygwin AT cygwin DOT com >To: Nrusinh Ambekar >CC: cygwin AT cygwin DOT com >Subject: Re: problem - if statement in shell script gives opposite results >with new bash >Date: Wed, 2 Oct 2002 10:18:01 -0400 (EDT) > >Nrusinh, > >On Wed, 2 Oct 2002, Nrusinh Ambekar wrote: > > > Hi, > > I have recently downloaded new cygwin. I am getting incorrect results >when I > > run simple shell script using bash. The same shell script runs fine with >old > > cygwin bash. > > > > Your help is really appreciated. > > thanks, > > Nrusinh > >A quick correction: it's not the if statement that gives the opposite >results, it's the "test" command (the "[...]" construct) that returns an >"opposite" value. This having been said, there are a couple of problems >with your script (see below): > > > The script is as follows > > > > #!/usr/local/bin/bash > ^ >Why is your bash in /usr/local/bin? It's normally installed in /bin (or >/usr/bin, which is usually the same under Cygwin). > > > myfunc() > > { > > local item=$1 > > shift 1 > > local list=" $* " > > echo "item is" > > echo $item > > echo "list is" > > echo $list > > if [ "${item}" = "${list}" ] || [ "${list#"* ${item} *"}" != "${list}" ] >|| [ "${list#"${item} "}" != "${list}" ] || [ "${list%" ${item}"}" != >"${list}" ] > ^ >Your quoting seems off here. Quotes do not nest in bash (or any other >shells)... Besides, if you're using the curlies ("{}") to delimit >variable substitutions, you don't need to quote stuff inside the curlies. > >Also, your prefix/suffix matches don't seem well-constructed. The first >one, frankly, doesn't make sense at all - bash cannot match regular >expressions open at both ends. You're better off with something like >this (which works, btw): > >if [ "${item}" = "${list}" ] || [ "${list#* ${item} }" != "${list}" ] || [ >"${list% ${item} *}" != "${list}" ] > > > then > > echo "found" > > else > > echo "not found" > > fi > > } > > > > myfunc CECA OTA OEA CECA > >So, this is not a bash bug after all. I'm really not sure why the script >used to work... You probably relied on some bug that was fixed in the >current version. And, unless you had a link from /usr/local/bin/bash to >/usr/bin/bash (or ran this explicitly with "bash script.bash"), this >wouldn't have worked at all. > Igor >-- > http://cs.nyu.edu/~pechtcha/ > |\ _,,,---,,_ pechtcha AT cs DOT nyu DOT edu >ZZZzz /,`.-'`' -. ;-;;,_ igor AT watson DOT ibm DOT com > |,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski > '---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow! > >"Water molecules expand as they grow warmer" (C) Popular Science, Oct'02, >p.51 > > >-- >Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple >Bug reporting: http://cygwin.com/bugs.html >Documentation: http://cygwin.com/docs.html >FAQ: http://cygwin.com/faq/ _________________________________________________________________ Join the world’s largest e-mail service with MSN Hotmail. http://www.hotmail.com -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/