Re: in f13 =~ no longer working in bash

2010-06-09 Thread James Findley
On 06/08/2010 08:05 PM, Richard W.M. Jones wrote:
 On Tue, Jun 08, 2010 at 02:14:12PM +0200, Farkas Levente wrote:
 hi,
 =~ no longer working in bash. just try this little line:
 -
 if [[ abc =~ abc.* ]]; then echo inside; else echo outside; fi
 -
 this give inside up to fedora-12, but it gives
 outside in fedora-13.
 imho it's a serious changes since all shell script will fail which use
 =~ :-(
 is there any reason for this? or any quick fixes?

 This bit us in libguestfs too, where we'd used the bash extension
 without thinking that they'd break it on us.

 The full fix is *not* just quote removal.

 cf. our first fix:
 http://git.annexia.org/?p=libguestfs.git;a=commitdiff;h=457fccae1b665347f81045e8c7a3309d8328c4fc

 and out later, complete fix:
 http://git.annexia.org/?p=libguestfs.git;a=commitdiff;h=4891ff9945177e8666af8381d1e0a54b8ce363e2

 Huge pain in the neck .. bash should retain backwards compatibility,
 even for non-POSIX extensions.

 Rich.


This actually stems from using poor bash syntax in the first place. 
Inside [[ foo ]] (as opposed to [ foo ]) you should not quote parameters.

No wordsplitting or glob expansion is done inside [[ ]], so there is no 
need for those quotes.  Get rid of them, and woosh! it works!

For example, from your script, you had:
[[ $path =~ '^\./etc' || $path =~ '^./dev' || $path =~ '^\./var' ]]
If you had written this properly as:
[[ $path =~ ^\./etc || $path =~ ^\./dev || $path =~ ^\./var ]]
It would have continued to work just fine.

The old behaviour may have worked on older bash versions, but it was 
always undefined, and relying on undefined behaviour in any programming 
language is a great way to get bitten on the butt later on.

-siXy
-- 
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel


Re: in f13 =~ no longer working in bash

2010-06-08 Thread David Michael
On Tue, Jun 8, 2010 at 8:14 AM, Farkas Levente lfar...@lfarkas.org wrote:
 hi,
 =~ no longer working in bash. just try this little line:
 -
 if [[ abc =~ abc.* ]]; then echo inside; else echo outside; fi
 -
 this give inside up to fedora-12, but it gives
 outside in fedora-13.
 imho it's a serious changes since all shell script will fail which use
 =~ :-(
 is there any reason for this? or any quick fixes?

Try removing the quotes from the regular expression, or at least the
asterisk.  Alternatively, you can use something like `grep -Eq abc.*
 abc` for extended regular expressions with the expected
quoted-token behavior.
-- 
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel


Re: in f13 =~ no longer working in bash

2010-06-08 Thread Sergeev Pavel
08.06.10, 16:14, Farkas Levente lfar...@lfarkas.org:

 hi,
  =~ no longer working in bash. just try this little line:
  -
  if [[ abc =~ abc.* ]]; then echo inside; else echo outside; fi
  -
  this give inside up to fedora-12, but it gives
  outside in fedora-13.
  imho it's a serious changes since all shell script will fail which use
  =~ :-(
  is there any reason for this? or any quick fixes?
  thanks in advance.
  regards.
  
  
Hi,

[vour...@localhost ~]$ shopt -s compat31
[vour...@localhost ~]$ if [[ abc =~ abc.* ]]; then echo inside; else echo 
outside; fi
inside

Regards,
-- 
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel


Re: in f13 =~ no longer working in bash

2010-06-08 Thread Andreas Schwab
Farkas Levente lfar...@lfarkas.org writes:

 hi,
 =~ no longer working in bash. just try this little line:
 -
 if [[ abc =~ abc.* ]]; then echo inside; else echo outside; fi
 -

See question E14 in the Bash FAQ.

Andreas.

-- 
Andreas Schwab, sch...@redhat.com
GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84  5EC7 45C6 250E 6F00 984E
And now for something completely different.
-- 
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel


Re: in f13 =~ no longer working in bash

2010-06-08 Thread Richard W.M. Jones
On Tue, Jun 08, 2010 at 02:14:12PM +0200, Farkas Levente wrote:
 hi,
 =~ no longer working in bash. just try this little line:
 -
 if [[ abc =~ abc.* ]]; then echo inside; else echo outside; fi
 -
 this give inside up to fedora-12, but it gives
 outside in fedora-13.
 imho it's a serious changes since all shell script will fail which use
 =~ :-(
 is there any reason for this? or any quick fixes?

This bit us in libguestfs too, where we'd used the bash extension
without thinking that they'd break it on us.

The full fix is *not* just quote removal.

cf. our first fix:
http://git.annexia.org/?p=libguestfs.git;a=commitdiff;h=457fccae1b665347f81045e8c7a3309d8328c4fc

and out later, complete fix:
http://git.annexia.org/?p=libguestfs.git;a=commitdiff;h=4891ff9945177e8666af8381d1e0a54b8ce363e2

Huge pain in the neck .. bash should retain backwards compatibility,
even for non-POSIX extensions.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top
-- 
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel