need help in shell script
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > need help in shell script




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    need help in shell script  
jagadish


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-28-04 08:32 AM

In one of my script, I would like to check the RETCD like this,

If the RETCD is not 0 and (RETCD is not 2310 or 2314 )
I want it do something in my script.

I have written a small script for that, but it is telling me syntax error.
Can somebody fix this or you may write all the way newone and provide me.

#!/bin/ksh

echo "type a number a"

read a
let RETCD=a
if [ $RETCD -ne 0  &&  [[ $RETCD -ne 2314 || $RETCD -ne 2310 ]] 
]
then
echo "the retcd is not 0 or 2314 or 2310"
else
echo "the retcd is $RETCD"
fi

If I run the above script, I get this error. It is not accepting the syntax.
u060wdb1:/tmp>./1.ksh
type a number a
2333
./1.ksh[8]: 0403-057 Syntax error at line 9 : `]' is not expected.
u060wdb1:/tmp>


Thanks in advnace





[ Post a follow-up to this message ]



    Re: need help in shell script  
Stephane CHAZELAS


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-28-04 08:32 AM

2004-09-23, 10:59(-07), jagadish:
[...]
> #!/bin/ksh
>
> echo "type a number a"
>
> read a
> let RETCD=a
> if [ $RETCD -ne 0  &&  [[ $RETCD -ne 2314 || $RETCD -ne 2310 ]
] ]
> then
>         echo "the retcd is not 0 or 2314 or 2310"
> else
>        echo "the retcd is $RETCD"
> fi
[...]

Either:

case $RETCD in
0|2314|2310) print "the retcd is $RETCD";;
*) print "the retcd is not 0 or 2314 or 2310";;
esac

or

if ((RETCD != 0 && RETCD != 2314 && RETCD != 2310)); then
echo "the retcd is not 0 or 2314 or 2310"
else
echo "the retcd is $RETCD"
fi

--
Stephane





[ Post a follow-up to this message ]



    Re: need help in shell script  
Chris F.A. Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-03-04 02:12 AM

On 2004-09-27, jagadish wrote:
> Stephane CHAZELAS <this.address@is.invalid> wrote in message news:<slrncl6
457.1sg.stephane.chazelas@spam.is.invalid>... 

[please don't top post]
[vbcol=seagreen]
> I think, I have not put my requirement properly.
>
> I am looking for this,
>
> if [ $RETCD -ne 0  &&  [[ $RETCD -ne 2314 || $RETCD -ne 2310 ]
] ]
>
> I want to check two condtions
>
> RETCD not equal to 0 and RETCD not equal 2314
>
>               or
> RETCD not equal to 0 and RETCD not equal to 2310

Which is the same as satisfying all of $RETCD -ne 0, $RETCD -ne
2310, and $RETCD -ne 2314.

Which is what Stephane's case statement does.

If you don't agree, please provide a value for $RETCD which
satisfies your conditions, but not Stephane's.

> The replied solution doesnot meet my requirement.They only check for
> one of the three values, but I want to test for combination like
> above.

In what way does it not satisfy the requirement?

--
Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
 ========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License





[ Post a follow-up to this message ]



    Re: need help in shell script  
Paul Jarc


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-03-04 02:12 AM

"Chris F.A. Johnson" <cfajohnson@gmail.com> wrote:
> On 2004-09-27, jagadish wrote: 
>
>      Which is the same as satisfying all of $RETCD -ne 0, $RETCD -ne
>      2310, and $RETCD -ne 2314.

No, it's the same as satisfying $RETCD -ne 0.  Which makes me think
the OP does not have a clear idea of what the requirements actually
are.


paul





[ Post a follow-up to this message ]



    Re: need help in shell script  
Paul Jarc


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-04-04 11:01 PM

jdara1m@yahoo.com (jagadish) wrote:[vbcol=seagreen]
> if [ $RETCD -ne 0  &&  [[ $RETCD -ne 2314 || $RETCD -ne 2310 ]] ][/vbc
ol]

One way of fixing your syntax would look like this:
if [ "$RETCD" != 0 ] && { [ "$RETCD" != 2314 ] || [ "$RETCD
" != 2310 ]; }

But the { ... } part is always true (2310 satisfies the first part,
and thus the whole; 2314 satisfies the second part, and thus the
whole; every other value satisfies both parts, and thus the whole), so
this is equivalent to:
if [ "$RETCD" != 0 ]


paul





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:01 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register