[20190419]bash單雙引號問題.txt

lfree發表於2019-04-22

[20190419]bash單雙引號問題.txt


--//上午除錯bash shell時遇到的問題。


$ sqlplus -s -l / as sysdba <<< '@ shared_latch.txt "test shared non-parent l0" 1 1 2  x 1' >| /tmp/xx.txt


$ cat /tmp/xx.txt

old   1: select decode(lower('&&5'),'s',8,'x',16,'8',8,'16',16) vmode from dual

new   1: select decode(lower('x'),'s',8,'x',16,'8',8,'16',16) vmode from dual


     VMODE

----------

        16


old   1: SELECT addr laddr FROM v$latch_parent WHERE NAME='&&1'

new   1: SELECT addr laddr FROM v$latch_parent WHERE NAME='test shared non-parent l0'

LADDR

----------------

0000000060009A18


Statement processed.

Function returned 1

Function returned 0

--//沒有問題。如果寫成指令碼如下,我想使用<<<語法的主要原因是shared_latch.txt指令碼最後沒有exit語句。

--//如果我直接這樣寫sqlplus -s -l / as sysdba @ shared_latch.txt "test shared non-parent l0" 1 1 2  x 1

--//在完成後是無法退出的。

$ cat shared_latch.txt

/* 引數如下: @ shared_latch.txt latch_name willing why where mode sleep_num */

--//connect / as sysdba

col laddr new_value laddr

col vmode  new_value vmode

select decode(lower('&&5'),'s',8,'x',16,'8',8,'16',16) vmode from dual ;

SELECT addr laddr FROM v$latch_parent WHERE NAME='&&1';

oradebug setmypid

oradebug call kslgetsl_w 0x&laddr &&2 &&3 &&4  &vmode

host sleep &&6

oradebug call kslfre 0x&laddr

--//exit


--//如果寫成如下:

$ cat p7.sh

#! /bin/bash

vdate=$(date '+%Y%m%d%H%M%S')

echo $vdate

a="$1"

echo $a


source peek.sh "$1" 20 | timestamp.pl >| /tmp/peekx_${vdate}.txt &


sqlplus -s -l / as sysdba <<EOF  >| /tmp/latch_free_${vdate}.txt &

$(seq 20 | xargs -I {} echo -e '@latch_free \n host sleep 1')

EOF


sleep 1

# 引數如下: @ exclusive_latch.txt latch_name willing why where  sleep_num

sqlplus / as sysdba <<< '@ shared_latch.txt "$a" 1 4 5 x 10' >| /tmp/xx.txt &

p=$!

strace -fttT  -p $p -o /tmp/pp_${vdate}_${p}.txt > /dev/null &

sleep 2

sqlplus / as sysdba <<< '@ shared_latch.txt "$a" 1 6 7 s 5' >> /tmp/xx.txt &

p=$!

strace -fttT  -p $p -o /tmp/pp_${vdate}_${p}.txt > /dev/null &

wait


--//檢查 /tmp/xx.txt 內容,可以發現帶入的內容並沒有轉換。

...


old   1: SELECT addr laddr FROM v$latch_parent WHERE NAME='&&1'

new   1: SELECT addr laddr FROM v$latch_parent WHERE NAME='$a'


--//可以發現外面的單引號發生作用,導致裡面的雙引號的內容不會轉換,如何解決這個問題呢?

--//修改如下正常:

$ cat p7.sh

#! /bin/bash

vdate=$(date '+%Y%m%d%H%M%S')

echo $vdate

a="$1"

echo $a


source peek.sh "$1" 20 | timestamp.pl >| /tmp/peekx_${vdate}.txt &


sqlplus -s -l / as sysdba <<EOF  >| /tmp/latch_free_${vdate}.txt &

$(seq 20 | xargs -I {} echo -e '@latch_free \n host sleep 1')

EOF


sleep 1

# 引數如下: @ exclusive_latch.txt latch_name willing why where  sleep_num

sqlplus / as sysdba <<< "@ shared_latch.txt '"$a"' 1 4 5 x 10" > /dev/null &

p=$!

strace -fttT  -p $p -o /tmp/pp_${vdate}_${p}.txt > /dev/null &

sleep 2

sqlplus / as sysdba <<< "@ shared_latch.txt '"$a"' 1 6 7 s 5"  > /dev/null &

p=$!

strace -fttT  -p $p -o /tmp/pp_${vdate}_${p}.txt > /dev/null &

wait


 $ . p7.sh "test shared non-parent l0"

20190419153743

test shared non-parent l0

Process 35246 attached - interrupt to quit

Process 35249 attached

Process 35252 attached

Process 35246 suspended

Process 35255 attached - interrupt to quit

Process 35257 attached

Process 35246 resumed

Process 35252 detached

Process 35276 attached

Process 35255 suspended

Process 35246 detached

Process 35249 detached

Process 35255 resumed

Process 35276 detached

Process 35255 detached

Process 35257 detached

[1]   Done                    source peek.sh "$1" 20 | timestamp.pl >|/tmp/peekx_${vdate}.txt

[3]   Done                    sqlplus / as sysdba <<< "@ shared_latch.txt '"$a"' 1 4 5 x 10" > /dev/null

[4]   Done                    strace -fttT -p $p -o /tmp/pp_${vdate}_${p}.txt > /dev/null

[5]-  Done                    sqlplus / as sysdba <<< "@ shared_latch.txt '"$a"' 1 6 7 s 5" > /dev/null

[6]+  Done                    strace -fttT -p $p -o /tmp/pp_${vdate}_${p}.txt > /dev/null

[2]+  Done                    sqlplus -s -l / as sysdba  >|/tmp/latch_free_${vdate}.txt <<EOF

$(seq 20 | xargs -I {} echo -e '@latch_free \n host sleep 1')

EOF

--//有時候這些細節問題經常搞暈掉,浪費許多時間。


$ grep sem /tmp/pp_20190419153743_352*

/tmp/pp_20190419153743_35246.txt:35249 15:37:54.919702 semctl(315588608, 34, SETVAL, 0x1) = 0 <0.000029>

/tmp/pp_20190419153743_35255.txt:35257 15:37:46.890699 semop(315588608, 0x7fff45fe1820, 1) = 0 <8.029049>


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

相關文章