[20200211]zsh的bug.txt

lfree發表於2020-02-12

[20200211]zsh的bug.txt

--//上午測試sql文字計算full_hash_value,sql _id,hash_value,發現我以前寫的指令碼報錯。

1.環境
$ head -1 /etc/issue
Oracle Linux Server release 5.9

$ zsh --version
zsh 4.2.6 (x86_64-redhat-linux-gnu)

--//指令碼如下,使用zsh的目的是可以直接現實16進位制轉32進位制,寫法像這樣echo $(( [##32]16#$v2 )。至少目前bash不行。
$ cat sql_id.zsh
#! /bin/zsh
# calcucate sql_text of full_hash_value(16),hash_value(10),sql_id(32).
odebug=${ODEBUG:-0}

#sql_text=${1}'\0'
sql_text=${1}
v1=$(echo -e -n "$sql_text" | md5sum | sed 's/  -//' | xxd -r -p | od -t x4 |  sed   -n  -e 's/^0\+ //' -e 's/ //gp' | tr 'a-z' 'A-Z')
#v2=${v1:(-16):16}
#v3=${v2:(-8):8}
v2=$(echo "obase=16;ibase=16; $v1 % 10000000000000000" | bc| tr -d '\\\r\n')
v3=$(echo "obase=10;ibase=16; $v1 % 100000000" | bc| tr -d '\\\r\n')

if [ $odebug -eq 1 ] ; then
        echo v1=$v1 v2=$v2 v3=$v3
fi

echo "sql_text = $sql_text"
echo "full_hash_value(16) = $v1 "
echo "hash_value(10) = $v3 "
#echo "hash_value(10) = $(( 16#$v3 )) "

#res=$( echo $(( [##32]16#$v2 )) | tr $( echo {0..9} {A..V}| tr -d ' ') $(echo {0..9} {a..z} | tr -d 'eilo ') )
res=$( echo $(( [##32]16#$v2 )) | tr 'ABCDEFGHIJKLMNOPQRSTUV'  'abcdfghjkmnpqrstuvwxyz' )
echo "sql_id(32) = $(printf "%13s" $res | tr ' ' '0')"
echo "sql_id(32) = $(printf "%013s" $res )"

2.測試:
SELECT name
      ,hash_value
      ,full_hash_value
      ,namespace
      ,child_latch
      ,property hot_flag
      ,executions
      ,invalidations
  FROM v$db_object_cache
 WHERE name = 'select * from dept where deptno=10';

NAME                                     HASH_VALUE FULL_HASH_VALUE                  NAMESPACE  CHILD_LATCH HOT_FLAG   EXECUTIONS INVALIDATIONS
---------------------------------------- ---------- -------------------------------- ---------- ----------- ---------- ---------- -------------
select * from dept where deptno=10       2941143312 5196d0b7fe72e5ea7c59eeb2af4e4910 SQL AREA             0 HOTCOPY11           3             0
select * from dept where deptno=10       2941143312 5196d0b7fe72e5ea7c59eeb2af4e4910 SQL AREA         18704 HOTCOPY11           3             0
select * from dept where deptno=10        911274289 1431c45dbddbb9e74eaa74d53650f131 SQL AREA             0 HOT                 8             0
select * from dept where deptno=10        911274289 1431c45dbddbb9e74eaa74d53650f131 SQL AREA         61745 HOT                 8             0
select * from dept where deptno=10       3106222595 642c74f9bf38538acec7e363b9253203 SQL AREA             0 HOTCOPY7            1             0
select * from dept where deptno=10       3106222595 642c74f9bf38538acec7e363b9253203 SQL AREA         78339 HOTCOPY7            1             0

$ export ODEBUG=1
$ ./sql_id.zsh 'select * from dept where deptno=10\0.7'
v1=642C74F9BF38538ACEC7E363B9253203 v2=CEC7E363B9253203 v3=3106222595
sql_text = select * from dept where deptno=10.7
full_hash_value(16) = 642C74F9BF38538ACEC7E363B9253203
hash_value(10) = 3106222595
./sql_id.zsh:1: number truncated after 15 digits: CEC7E363B9253203
sql_id(32) = 0tv3y6sxt4nt0
sql_id(32) =  tv3y6sxt4nt0

--//full_hash_value,hash_value都可以對上。
$ zsh
% echo $(( [##32]16#11 ))
H
% echo $(( [##32]16#AA ))
5A

--//0xaa = 170

% bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
obase=32
170
 05 10
--//說明轉換正確。

% v2=CEC7E363B9253203
% echo $(( [##32]16#$v2))
zsh: number truncated after 15 digits: CEC7E363B9253203
PR3U6OTP4KP0

% v2=9EC7E363B9253203
%  echo $(( [##32]16#$v2))
zsh: number truncated after 15 digits: 9EC7E363B9253203
JR3U6OTP4KP0

% v2=7FFFFFFFFFFFFFFF
% echo $(( [##32]16#$v2))
7VVVVVVVVVVVV

% v2=8000000000000000
% echo $(( [##32]16#$v2))
zsh: number truncated after 15 digits: 8000000000000000
G00000000000
--//計算是丟棄了後面的0.

% v2=800000000000000
% echo $(( [##32]16#$v2))
G00000000000
--//估計運算元太大,操作範圍了。

3.在cygwin下測試:
$ zsh --version
zsh 5.5.1 (x86_64-unknown-cygwin)

$ ./sql_id.zsh 'select * from dept where deptno=10\0.7'
sql_text = select * from dept where deptno=10.7
full_hash_value(16) = 642C74F9BF38538ACEC7E363B9253203
hash_value(10) = 3106222595
./sql_id.zsh:25: number truncated after 15 digits: CEC7E363B9253203
sql_id(32) = 0tv3y6sxt4nt0
sql_id(32) =  tv3y6sxt4nt0
--//問題一樣。看來bash與zsh一樣,運算的數值不能太大,也不能稱為bug^_^。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2675191/,如需轉載,請註明出處,否則將追究法律責任。

相關文章