Unix Shell - need help on some test operations in if loop

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > November 2006 > need help on some test operations in if loop





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author need help on some test operations in if loop
atishay

2006-11-29, 1:30 am

I have a shell script in which i assign values to following 3 vars.

lastModifiedMonth=`\echo ${sccsDate}|cut -d '/' -f 2`
lastModifiedDate=`\echo ${sccsDate}|cut -d '/' -f 3`
lastModifiedYear=`\echo ${sccsDate}|cut -d '/' -f 1

if i have a test condition like following
if [ "x${lastModifiedMonth}" != "x" -a "x${lastModifiedDate} !=
"x" -a "x${lastModifiedYear}" != "x" ] ; then

i get following error in the script.

listChanges.sh: syntax error at line 29: `end of file' unexpected

i change it to
if [ "x${lastModifiedMonth}" != "x" ] ; then

now it works.


What am in doing wrong?

cheers..atishay

Chris F.A. Johnson

2006-11-29, 7:28 am

On 2006-11-29, atishay wrote:
> I have a shell script in which i assign values to following 3 vars.
>
> lastModifiedMonth=`\echo ${sccsDate}|cut -d '/' -f 2`
> lastModifiedDate=`\echo ${sccsDate}|cut -d '/' -f 3`
> lastModifiedYear=`\echo ${sccsDate}|cut -d '/' -f 1
>
> if i have a test condition like following
> if [ "x${lastModifiedMonth}" != "x" -a "x${lastModifiedDate} !=
> "x" -a "x${lastModifiedYear}" != "x" ] ; then
>
> i get following error in the script.
>
> listChanges.sh: syntax error at line 29: `end of file' unexpected


That error usually (if not always) means you are missing a closing
character: quotes, parentheses, etc.

In this case, you are missing a closing double quote after
"x${lastModifiedDate}; it shold be:

if [ "x${lastModifiedMonth}" != "x" -a "x${lastModifiedDate}" != "x" -a "x${lastModifiedYear}" != "x" ] ; then

> i change it to
> if [ "x${lastModifiedMonth}" != "x" ] ; then
>
> now it works.
>
>
> What am in doing wrong?


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
atishay

2006-11-29, 7:28 am

oh! i should change my glass..
thanks..chris

Chris F.A. Johnson wrote:
> On 2006-11-29, atishay wrote:
>
> That error usually (if not always) means you are missing a closing
> character: quotes, parentheses, etc.
>
> In this case, you are missing a closing double quote after
> "x${lastModifiedDate}; it shold be:
>
> if [ "x${lastModifiedMonth}" != "x" -a "x${lastModifiedDate}" != "x" -a "x${lastModifiedYear}" != "x" ] ; then
>
>
> --
> Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
> ===== My code in this post, if any, assumes the POSIX locale
> ===== and is released under the GNU General Public Licence


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com