Bash pattern matching seems to be changed after bash-3.2-32.el5
Issue
- Bash pattern matching seems to be changed after
bash-3.2-32.el5 - The scripts written for
bashshell do not honour the regular expressions correctly in the recentbashversions. - The below script works as expected in
bash-3.2-32.el5
[root@localhost ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.8 (Tikanga)
[root@localhost ~]# rpm -qa | grep bash
bash-3.2-32.el5
[root@localhost ~]# ./regex.sh
SUCCESS: SUDO updated
SUCCESS: SUDO updatedEEEEEEEEEEE
SUCCESS: SUDO updated
xxx
zzzzz
yyyyyyyyy
- However, the same script does not honour the regular expressions correctly in
bash-4.1.2-15.el6_4.x86_64
[root@localhost ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.5 (Santiago)
[root@localhost ~]# rpm -qa | grep bash
bash-4.1.2-15.el6_4.x86_64
[root@localhost ~]# cat regex.sh
#!/bin/bash
UpdateSUDOresult="SUCCESS: SUDO updated"
echo ${UpdateSUDOresult}
echo ${UpdateSUDOresult}EEEEEEEEEEE
echo ${UpdateSUDOresult} | grep "^SUCCESS: SUDO updated$"
if [[ ${UpdateSUDOresult} =~ '^SUCCESS: SUDO updated$' ]] ; then echo xxx; fi
if [[ ${UpdateSUDOresult} =~ 'SUCCESS: SUDO updated$' ]] ; then echo zzzzz; fi
if [[ ${UpdateSUDOresult} =~ 'SUCCESS: SUDO updated' ]] ; then echo yyyyyyyyy; fi
[root@localhost ~]# ./regex.sh
SUCCESS: SUDO updated
SUCCESS: SUDO updatedEEEEEEEEEEE
SUCCESS: SUDO updated
yyyyyyyyy
Environment
- Red Hat Enterprise Linux 5/6/7
- bash-4.1.2-15.el6_4.x86_64
- bash-3.2-32.el5
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
