ksh: eval: syntax error: `((' unexpected

Hi, i’ve got an error (eval: syntax error: `((’ unexpected ) on u+m (but working), while working fine on u+ 2012. Now i’m not sure is it my fault or bug. u+m is yesterday compilation.

integer i=0
for .. in ..
...
((i++))#error

What is more funny, if i redirect error to /dev/null it doesn’t show error on u+m but stops working on u+ 2012: ((i++)) 2> /dev/null

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16

Commits related to this issue

Most upvoted comments

There was another silly mistake in the last version, here’s a corrected one. @DesantBucie @posguy99

_do_autocd()
{
        if      (($#==1)) && ! command -v "$1" >/dev/null && [[ -d $1 ]]
        then    printf 'cd -- %q\n' "$1" >&2
                CDPATH= command cd -- "$1"
                return 2
        fi
}
trap '((!.sh.level)) && [[ ${.sh.command} != \(* && -o interactive ]] && eval "_do_autocd ${.sh.command}"' DEBUG

Try this. This version of the trap action assumes that ${.sh.command} will contain either properly shellquoted command arguments, or an arithmetic command starting with (( (but it’s enough to check for the initial ( as that alone would be a syntax error to eval after a prefix word). It also refuses to eval or run the function if the shell is not interactive, or if we’re currently executing a function (if ${.sh.level} is nonzero).

This does actually work on ksh 93u+, but not if you define a complicated prompt (such as your own) that executes command substitutions, as that kills the DEBUG trap on 93u+ due to one of the many bugs with that. Those bugs have been fixed on 93u+m.

_do_autocd()
{
        if      (($#==1)) && ! command -v "$1" >/dev/null && [[ -d $1 ]]
        then    printf 'cd -- %q\n' "$1" >&2
                CDPATH= command cd -- "$1"
                return 2
        fi
}
trap '((!.sh.level)) && [[ $1 != \(* && -o interactive ]] && eval "_do_autocd ${.sh.command}"' DEBUG

edit: Silly mistake: $1 != \(* should be ${.sh.command} != \(*.