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
signature.asc
Description: OpenPGP digital signature