Re: Bash regex issue

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

 



On 2/5/11 8:51 AM, Emmett Culley wrote:
> I have a bash script I've been using in CentOS that no longer works in Fedora 14. The pertinent lines are:
>
> mac=`echo $2 | tr a-z A-Z`
> if [[ "$mac" =~ '[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]' ]]; then
>    echo 'good'
> else
>    echo 'Invalid MAC address'
> fi
>
> In CentOS or RHEL5 setting parameter 2 = 00:00:00:00:af:df works as expected, but not in Fedora.  By adding -x to the first line of the script the output to the terminal in CentOS looks like this:
>
> ++ echo 00:00:00:00:af:df
> ++ tr a-z A-Z
> + mac=00:00:00:00:AF:DF
> + [[ 00:00:00:00:AF:DF =~ [0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F] ]]
> + echo good
> good
>
> In Fedora it looks like this:
>
> ++ echo 00:00:00:00:af:df
> ++ tr a-z A-Z
> + mac=00:00:00:00:AF:DF
> + [[ 00:00:00:00:AF:DF =~ \[0-9A-F]\[0-9A-F]:\[0-9A-F]\[0-9A-F]:\[0-9A-F]\[0-9A-F]:\[0-9A-F]\[0-9A-F]:\[0-9A-F]\[0-9A-F]:\[0-9A-F]\[0-9A-F] ]]
> + echo 'Invalid MAC address'
> Invalid MAC address
>
> Note the "\" before each "[" in the regular expression.
>
That is an error as BASH in FC14 is trying to escape the left bracket 
and should not be doing so.

Check the FC bugzilla and if there is not a bug report, file one.

James McKenzie

-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines

[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux