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 > Redhat > Fedora Development

 
 
LinkBack Thread Tools
 
Old 06-08-2010, 12:14 PM
Farkas Levente
 
Default in f13 =~ no longer working in bash

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.

--
Levente "Si vis pacem para bellum!"
--
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel
 
Old 06-08-2010, 12:29 PM
David Michael
 
Default in f13 =~ no longer working in bash

On Tue, Jun 8, 2010 at 8:14 AM, Farkas Levente <lfarkas@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
 
Old 06-08-2010, 12:34 PM
Sergeev Pavel
 
Default in f13 =~ no longer working in bash

08.06.10, 16:14, "Farkas Levente" <lfarkas@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,

[Vourhey@localhost ~]$ shopt -s compat31
[Vourhey@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
 
Old 06-08-2010, 12:34 PM
Andreas Schwab
 
Default in f13 =~ no longer working in bash

Farkas Levente <lfarkas@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, schwab@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
 
Old 06-08-2010, 07:05 PM
"Richard W.M. Jones"
 
Default in f13 =~ no longer working in bash

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=457fccae1b665347f 81045e8c7a3309d8328c4fc

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

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
 
Old 06-09-2010, 06:02 AM
Ville Skyttä
 
Default in f13 =~ no longer working in bash

On Tuesday 08 June 2010, Richard W.M. Jones wrote:

> The full fix is *not* just quote removal.
>
> cf. our first fix:
> http://git.annexia.org/?p=libguestfs.git;a=commitdiff;h=457fccae1b665347f 81
> 045e8c7a3309d8328c4fc
>
> and out later, complete fix:
> http://git.annexia.org/?p=libguestfs.git;a=commitdiff;h=4891ff9945177e866 6a
> f8381d1e0a54b8ce363e2
>
> Huge pain in the neck ..

FWIW these issues can sometimes (often?) be fixed by not using =~ at all,
either by using simple or extended (shopt -s extglob) globbing. A couple of
examples from the above:

- elif [[ "$path" =~ '^./lib/modules/' ]]; then
+ elif [[ "$path" == ./lib/modules/* ]]; then

- elif [[ "$file" =~ '^ld-[.0-9]+.so$' ]]; then
+ elif [[ "$file" == ld-+([.0-9]).so ]]; then

- elif [[ "$file" =~ '^libbfd-.*.so$' ]]; then
+ elif [[ "$file" == libbfd-*.so ]]; then
--
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel
 
Old 06-09-2010, 09:08 AM
James Findley
 
Default in f13 =~ no longer working in bash

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=457fccae1b665347f 81045e8c7a3309d8328c4fc
>
> and out later, complete fix:
> http://git.annexia.org/?p=libguestfs.git;a=commitdiff;h=4891ff9945177e866 6af8381d1e0a54b8ce363e2
>
> 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
 

Thread Tools




All times are GMT. The time now is 07:11 AM.

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