Search code examples
unixtcltcsh

badly placed ()'s error on a tcl/tcsh mixed script


I have the fallowing script, that at start is ran in tcsh and then ran in tcl. I get the error badly placed ()'s and don't understand why I get it.

    #!/usr/intel/bin/tcsh -f
    #\
    set TCL_VERSION="8.4.6o_64"
    #\
    setenv WORK_AREA_ROOT_DIR .
    #\
    exec ${CAD_ROOT}/tcl/${TCL_VERSION}/bin/wishx "$0" "$*" &

    lappend auto_path $env(KITE)/lib/pwidget
    lappend auto_path $env(KITE)/local_cad/nlview/tcl/
    lappend auto_path $env(KITE)/tcl/

    lappend auto_path $env(KITE)/gui/tcl/plotter
    lappend auto_path $env(KITE)/gui/tcl/graph-class

    package require Pwidget+
    package require Nlview

    package require sparam_view_graph

    package require BLT
    namespace import -force ::blt::bgexec

    source $env(KITE)/gui/tcl/sparam_view_env.tcl
    source $env(KITE)/tcl/sparamParser.tcl

    load $env(KITE)/lib/utils/libKitKiteUtilsTcl.so
    source $env(KITE)/lib/utils/qbnamex.tcl

    catch {delete object reg}
    TclRegistry reg -varname _app

    sparam_view_env "." $argv

The error message appears only after I get an indication that tcl (wish) started to run:

> bin/sparam_view_stand_alone.tcl /nfs/iil/proj/dt/epm16/work/imelam2/test/kite_check/kite/input/s2p/ISI_bit29.s2p
[1] 11474
Badly placed ()'s.

Solution

  • exec ${CAD_ROOT}/tcl/${TCL_VERSION}/bin/wishx "$0" "$*" &
    

    With a & at the end, this executes the TCL interpreter on the script, but keeps executing in csh. Since what follows is TCL syntax but not csh, this can't end right, and indeed csh complains when it reaches the line lappend auto_path $env(KITE)/lib/pwidget. Remove the &.

    Also, "$*" concatenates all the arguments and passes them in a single argument to wishx. To pass the arguments unchanged, make that ${*:q}. Also, if the wishx interpreter is not present for some reason, you should exit the script rather than keep executing it inside tcsh.

    exec "${CAD_ROOT}/tcl/${TCL_VERSION}/bin/wishx" "$0" ${*:q}
    #\
    exit 127
    

    Oh, and consider using Bourne shell syntax instead. Csh is not a very good scripting tool in the first place, and even for interactive use, tcsh has been surpassed by zsh since the early 1990s and bash caught up in the late 1990s. You'll find plenty of unix systems without csh nowadays, whereas every unix system has a Bourne-style shell as /bin/sh, and you'll be hard pressed to find one that's so old that it doesn't understand "$@".

    #!/bin/sh
    #\
    TCL_VERSION="8.4.6o_64"
    #\
    WORK_AREA_ROOT_DIR=.
    #\
    export WORK_AREA_ROOT_DIR
    #\
    exec "${CAD_ROOT}/tcl/${TCL_VERSION}/bin/wishx" "$0" "$@"
    #\
    exit