Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

if expression syntax error
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

Report this thread to moderator Post Follow-up to this message
Old Post
tgribbin
01-14-05 08:59 PM


Re: if expression syntax error
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


Report this thread to moderator Post Follow-up to this message
Old Post
Rakesh Sharma
01-14-05 08:59 PM


Re: if expression syntax error
"tgribbin" <tgribbin@buffalo.edu> 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





Report this thread to moderator Post Follow-up to this message
Old Post
William
01-14-05 08:59 PM


Re: if expression syntax error
William wrote:
> "tgribbin" <tgribbin@buffalo.edu> wrote in message
> news:cs8ok2$inv$1@prometheus.acsu.buffalo.edu...
> 
>
>
> 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 n
ot
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


Report this thread to moderator Post Follow-up to this message
Old Post
Michael Tosch
01-15-05 01:57 AM


Re: if expression syntax error
"Michael Tosch" <eedmit@NO.eed.SPAM.ericsson.PLS.se> 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



Report this thread to moderator Post Follow-up to this message
Old Post
William
01-16-05 08:57 PM


Re: if expression syntax error
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


Report this thread to moderator Post Follow-up to this message
Old Post
Rakesh Sharma
01-18-05 08:58 AM


Re: if expression syntax error
William wrote:
> "tgribbin" <tgribbin@buffalo.edu> wrote in message
> news:cs8ok2$inv$1@prometheus.acsu.buffalo.edu...
> 
>
>
> 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 n
ot
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


Report this thread to moderator Post Follow-up to this message
Old Post
Michael Tosch
01-18-05 08:58 AM


Re: if expression syntax error
"tgribbin" <tgribbin@buffalo.edu> 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





Report this thread to moderator Post Follow-up to this message
Old Post
William
01-19-05 08:59 AM


Re: if expression syntax error
"Michael Tosch" <eedmit@NO.eed.SPAM.ericsson.PLS.se> 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



Report this thread to moderator Post Follow-up to this message
Old Post
William
01-20-05 08:59 PM


Re: if expression syntax error
William wrote:
> "tgribbin" <tgribbin@buffalo.edu> wrote in message
> news:cs8ok2$inv$1@prometheus.acsu.buffalo.edu...
> 
>
>
> 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 n
ot
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


Report this thread to moderator Post Follow-up to this message
Old Post
Michael Tosch
01-20-05 08:59 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Unix Shell Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 08:20 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.