bash in RHEL5 fails with: syntax error near `@(6'
Issue
Consider following script:
#!/bin/bash
DATE=$(/bin/date +%m%d%Y)
CP=/bin/cp
MV=/bin/mv
AWK=/bin/awk
RELEASE=$(sed 's/.* \([0-9]\{1\}\.\?[0-9]*\) .*/\1/' /etc/redhat-release)
[[ $RELEASE == @(6)* ]] && CONF=/etc/rsyslog.conf || CONF=/etc/syslog.conf
[[ $RELEASE == @(6)* ]] && INIT=/etc/init.d/rsyslog || INIT=/etc/init.d/syslog
[[ -f $CONF ]] && $CP -p $CONF $CONF.${DATE} || exit 127
$AWK '$1 ~ /authpriv\.\*/{print"\nauthpriv.*\t\t\t\t\t\t@example.com"};{print}' $CONF > $CONF.bak
mv $CONF.bak $CONF
$INIT restart
The script works fine with bash on RHEL 6 but fails on RHEL 5. Works with ksh on RHEL 5 and RHEL 6.
This is the error with bash on RHEL5:
./x: line 7: syntax error in conditional expression: unexpected token `('
./x: line 7: syntax error near `@(6'
./x: line 7: `[[ $RELEASE == @(6)* ]] && CONF=/etc/rsyslog.conf || CONF=/etc/syslog.conf'
So what is the difference with bash?
Environment
- Red Hat Enterprise Linux (RHEL) 5
- bash-3.2
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.
