if expression syntax error

if expression syntax error

am 14.01.2005 16:31:13 von Tim Gribbin

Hello,

I'm getting a snytax error in a file sourced within a csh script (in
some cases only) when the csh script is run by a Computer Associates job
load product called Autosys. This if expression and error is within a
sourced file. So script.csh has a command "source my_env.env".
my_env.env contains the if statement.

Below is the statement and error:
--
if ( $script_path =~ *sandbox* ) then
if: Expression syntax
--
(The expression tries to determine if the string contains "sandbox".
The complexity of the string seems to have some affect on success or
failure).

In some cases the if statment processes okay, sometimes we see the error
above when the load script runs through Autosys.

For example when $script path contains
"local/sandbox/meta/loads/wd/script.csh" it works fine through Autosys.

On the other hand when the $script_path string is more complex like
"/local/sandbox/meta/loads/wd/script2.csh param1 param2" we see the
error message above.

From the command line it always works with either situation above. The
script is defined as #!/bin/csh -f. The logged in user default shell
is /bin/tcsh.


Two questions:
1. Does anyone have an idea what may be happening here? I can't
understand why I am receiving the error in one case but not the other
since the *.csh scripts seem to identical to the point that the error
occurs.
And even if you don't...
2. Does anyone know of an alternate expression that would be more
universally acceptable? Due to a time constraint I would be happy to
just rewrite the expression, get it working and resolve the source of
the problem perhaps with vendor help later.

The current statement is:
if ( $script_path =~ *sandbox* ) then
.....
else
....
endif

Thanks in advance for any help or insight!

Tim Gribbin
University at Buffalo

Re: if expression syntax error

am 14.01.2005 17:33:28 von Rakesh Sharma

tgribbin wrote:
> Hello,
>
> I'm getting a snytax error in a file sourced within a csh script (in
> some cases only) when the csh script is run by a Computer Associates
job
> load product called Autosys. This if expression and error is within
a
> sourced file. So script.csh has a command "source my_env.env".
> my_env.env contains the if statement.
>
> Below is the statement and error:
> --
> if ( $script_path =~ *sandbox* ) then
> if: Expression syntax
> --
> (The expression tries to determine if the string contains "sandbox".
> The complexity of the string seems to have some affect on success or
> failure).
>
> In some cases the if statment processes okay, sometimes we see the
error
> above when the load script runs through Autosys.
>


Quote your variables.

if ( "$script_path" =~ *sandbox* ) then
# ............. pathA

else

# ............. pathB

endif

Re: if expression syntax error

am 14.01.2005 17:33:34 von William

"tgribbin" wrote in message
news:cs8ok2$inv$1@prometheus.acsu.buffalo.edu...
> Hello,
>
> I'm getting a snytax error in a file sourced within a csh script (in
> some cases only) when the csh script is run by a Computer Associates job
> load product called Autosys. This if expression and error is within a
> sourced file. So script.csh has a command "source my_env.env".
> my_env.env contains the if statement.
>
> Below is the statement and error:
> --
> if ( $script_path =~ *sandbox* ) then
> if: Expression syntax

Does it work better if you write it as:

if ( "$script_path" =~ "*sandbox*" ) then

Without the quotes, I would expect it to work only if script_path
did NOT contain a space (or a few other special characters).
Quoting anything that might induce file globbing is also a good
idea. (Ever tried it in a directory that had a file whose name
contained 'sandbox'?) -Wm

Re: if expression syntax error

am 14.01.2005 21:29:16 von Michael Tosch

William wrote:
> "tgribbin" wrote in message
> news:cs8ok2$inv$1@prometheus.acsu.buffalo.edu...
>
>>Hello,
>>
>>I'm getting a snytax error in a file sourced within a csh script (in
>>some cases only) when the csh script is run by a Computer Associates job
>>load product called Autosys. This if expression and error is within a
>>sourced file. So script.csh has a command "source my_env.env".
>>my_env.env contains the if statement.
>>
>>Below is the statement and error:
>>--
>>if ( $script_path =~ *sandbox* ) then
>>if: Expression syntax
>
>
> Does it work better if you write it as:
>
> if ( "$script_path" =~ "*sandbox*" ) then
>
> Without the quotes, I would expect it to work only if script_path
> did NOT contain a space (or a few other special characters).
> Quoting anything that might induce file globbing is also a good
> idea. (Ever tried it in a directory that had a file whose name
> contained 'sandbox'?) -Wm

True that the variable needs "quoting", but in this case the globbing does not
happen in the token parser but inside the =~ operator, which is intended and
must not be escaped.

So correct is what Rakesh Sharma suggested:

if ( "$script_path" =~ *sandbox* ) then

This is quite different from

if ( "$script_path" == "*sandbox*" ) then

where the globbing happens in the token parser, and files in the current
directory are matched.
Not logical? So is C-shell.

--
Michael Tosch @ hp : com

Re: if expression syntax error

am 16.01.2005 19:25:56 von William

"Michael Tosch" wrote in message
news:cs9a2r$jjd$1@aken.eed.ericsson.se...

> True that the variable needs "quoting", but in this case the globbing does
not
> happen in the token parser but inside the =~ operator, which is intended
and
> must not be escaped.
>
> So correct is what Rakesh Sharma suggested:
>
> if ( "$script_path" =~ *sandbox* ) then
>
> This is quite different from
>
> if ( "$script_path" == "*sandbox*" ) then
>
> where the globbing happens in the token parser, and files in the current
> directory are matched.
> Not logical? So is C-shell.

One reason I don't use c shell. Didn't know that about
the =~ operator. Live and learn (and avoid :-) -Wm