lijo george
2015-05-17 21:23:09 UTC
I observed a syntax error with a script in ksh versions starting from
2012-08-01.
A minimal test case is given below.
Basically if the pattern "[()]" is used as field separator in awk, it
throws a syntax error.
# ksh --version
version sh (AT&T Research) 93u+ 2012-08-01
# cat test-simple.ksh
NAWK=/usr/bin/nawk
TEST="abc(def)g)"
A="`echo $TEST | $NAWK '
BEGIN{
FS = "[()]"
}
/^a/ {
print $1
}
END{
#print $2
}'`"
print $A
# ksh test-simple.ksh
test-simple.ksh: line 2: syntax error at line 5: `(' unexpected
This used to work in the 2011-02-08 version.
Is this a bug or expected behaviour.
From the sh_lex function in the lex.c file, I can see that there is a check
added for the pattern "[(" given below.
case S_EPAT:
epat:
if(fcgetc(n)==LPAREN && c!='[')
But in the earlier version(2011-02-08), the corresponding check was
case S_EPAT:
epat:
if(fcgetc(n)==LPAREN)
So I guess the extra check was added for some specific reason. In that
case, could someone please let me know the reason why this was added and
the syntax error is thrown.
Thanks,
Lijo
2012-08-01.
A minimal test case is given below.
Basically if the pattern "[()]" is used as field separator in awk, it
throws a syntax error.
# ksh --version
version sh (AT&T Research) 93u+ 2012-08-01
# cat test-simple.ksh
NAWK=/usr/bin/nawk
TEST="abc(def)g)"
A="`echo $TEST | $NAWK '
BEGIN{
FS = "[()]"
}
/^a/ {
print $1
}
END{
#print $2
}'`"
print $A
# ksh test-simple.ksh
test-simple.ksh: line 2: syntax error at line 5: `(' unexpected
This used to work in the 2011-02-08 version.
Is this a bug or expected behaviour.
From the sh_lex function in the lex.c file, I can see that there is a check
added for the pattern "[(" given below.
case S_EPAT:
epat:
if(fcgetc(n)==LPAREN && c!='[')
But in the earlier version(2011-02-08), the corresponding check was
case S_EPAT:
epat:
if(fcgetc(n)==LPAREN)
So I guess the extra check was added for some specific reason. In that
case, could someone please let me know the reason why this was added and
the syntax error is thrown.
Thanks,
Lijo