shellif-statementopen-sourcetcltclsh

missing operand at _@_ in tcl script


in if condition I want to check whether the string contains the pattern, but i'm getting following error. missing operand at _@_ in expression " $extra_url eq _@_*user-new* " (parsing expression " $extra_url eq *user-n...") invoked from within "if { $extra_url eq *user-new* } {

code is as follows :

if { $extra_url eq *user-new* } {
     ds_add rp [list notice "File $root/$extra_url: Not found" $startclicks [clock clicks -milliseconds]]
     ds_add rp [list transformation [list notfound "$root / $extra_url" $val] $startclicks [clock clicks -milliseconds]]

 }

here I'm checking whether the extra_url string contains "user_new". I don't know whether I'm doing it right. please help.


Solution

  • Your problem is on this line:

    if { $extra_url eq *user-new* } {
    

    The issue is that the expression parser treats the first * of *user-new* as a multiply operator, and you've got two binary operators in a row without a value-token in between, which is illegal syntax. Indeed, to the expression parser, you might as well have written:

    $extra_url eq * user - new *
    

    OK, that's only after tokenizing, and has other problems after the double operator, namely unrecognised barewords and a trailing binary operator; the parse will fail. (Yes, the expression parser is a pretty traditional parser, not entirely different (albeit simpler than) those used to parse C or Java or …)

    I'm guessing you actually want either string equality with a literal token (put the token in {braces} or "double-quotes") or you want to use a command to test for some more complex case, such as a glob match with string match. Thus, pick one of these:

    if { $extra_url eq {*user-new*} } {
    
    if { $extra_url eq "*user-new*" } {
    
    if { [string match *user-new* $extra_url] } {