On Tue, Jan 19, 2010 at 9:10 PM, Eric Blake <e...@byu.net> wrote: > According to salih k on 1/16/2010 7:32 AM: > > Piece of Script > > -------------------------- > > > > /isnum=`awk -F$delim '$1=="BH"{print $5}' $fil`/ > > / > > That's still not exactly what you ran (you marked it up afterwards), but > it is close enough, I suppose. > > > int_num=`echo -e $isnum | cut -f1 -d'.'` > > echo -e is not portable. And if all you are trying to do is grab > everything before the first '.', you can do that without even forking: > > int_num=${isnum%%.*} > > But using a more efficient implementation won't change the net result of > your script, at least on systems where echo -e does what you wanted. > > > add_num=`expr $int_num + 1 1>/dev/null 2>&1` > > This line sets add_num to the empty string (because there is no output > from expr). Why run a command substitution if there won't be any output? > Also, your lack of shell quoting could cause you grief; it would be more > robust to use "$int_num" rather than $int_num. The following is similar > to your above line, but safer: > > add_num= > expr "$int_num" + 1 >/dev/null 2>&1 > kms=$? > > And even more efficiently, you can get the same results without forking, > by following my earlier advice: > > case $int_num in > *[!0-9]*) kms=1; echo non-numeric;; > *) kms=0; echo numeric;; > esac > > But again, switching to a more efficient implementation shouldn't seem to > have any bearing on your results. > > > kms=$? > > # if [ "$?" -ne "0" ] > > if [ "$kms" -ne "0" ] > > then > > log_msg "Debug msg4.new1 File has expr pstat $kms int_num is > > $int_num" > > Well, I don't see anything obvious about why you are seeing this: > > > Debug msg3.1 File FILE1 has int_num1 28 has ps 0 > > Debug msg4.new1 File has expr pstat 51198 int_num is 28 > ... > > Debug msg3.1 File FILE2 has int_num1 1 has ps 0 > > then again, you post-formatted the output, too (notice the inconsistent > spacing), and you didn't post the definition of log_msg. So who knows > what else your post-formatting has changed, such that we aren't seeing > EXACTLY what happened to you. > > But if it is a bug, then the bug is in your /bin/sh and not in expr. And > if you really do have a buggy shell, then there's nothing this list can do > to help you. > > > Is it because add_num=`expr $int_num + *1 1>/dev*/null 2>&1` whether i > > have to chanage it to > > add_num=`expr $int_num + *1 >*/dev/null 2>&1`? > > The change between '>/dev/null' and '1>/dev/null' has no effect - they are > strictly equivalent in shell programming. You may be benefited by doing > more homework on shell programming. But so far, you have failed to show > any evidence of a bug in expr. And inserting spurious * into the lines > doesn't make your example any easier to attempt and reproduce. > > -- > Don't work too hard, make some time for fun as well! > > Eric Blake e...@byu.net > > Hi, Thats fine but I did not got the answer why the exit status shows more than 255 during first run , ie exit status is 51198 even though the argument to expr int_num is 28 and in some cases it is 1552 even though the argument to expr int_num is 1. To show this one i have provided the log
*> Debug msg3.1 File FILE1 has int_num1 28 has ps 0 > Debug msg4.new1 File has expr pstat 51198 int_num is 28 ... * *> Debug msg3.1 File FILE2 has int_num1 1 has ps 0* * function *log_msg log_msg() { echo -e $* | tee -a $LOG } LOG=$LOG_DIR and $BASE/log--afile name from thios i provided the log So you are saying that this will not happen but this happened that y the log.What else I can provide. As a solution am asking whether I can check *if [ $kms -eq 1 -o $kms –eq 2 –o $kms –eq 3 ] *instaed of *if [ "$kms" -ne "0" ]* as the mannual says *info expr|more Exit status:* * 0 if the expression is neither null nor 0, 1 if the expression is null or 0, 2 if the expression is syntactically invalid, 3 if an error occurred.* as the manager is not happy to change the command ( case $int_num in *[!0-9]*|'') non nume ;;))as this was working in unix and also this issue happens in rare.we don t think issue in script.The rest of the code is for different purpose if u want that also i dont know what advantage we will get.The same files loaded without any issue in the second time.!!! Please advise Thanks, Salih