|
Home > Archive > Unix Shell > October 2004 > need help in shell script
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 in shell script
|
|
| jagadish 2004-09-28, 3: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
| |
| Stephane CHAZELAS 2004-09-28, 3: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
| |
| Chris F.A. Johnson 2004-10-02, 9:12 pm |
| On 2004-09-27, jagadish wrote:
> Stephane CHAZELAS <this.address@is.invalid> wrote in message news:<slrncl6457.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
| |
| Paul Jarc 2004-10-02, 9:12 pm |
| "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
| |
| Paul Jarc 2004-10-04, 6:01 pm |
| jdara1m@yahoo.com (jagadish) wrote:
> if [ $RETCD -ne 0 && [[ $RETCD -ne 2314 || $RETCD -ne 2310 ]] ]
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
|
|
|
|
|