ITPub博客

首页 > Linux操作系统 > Linux操作系统 > [20190419]bash单双引号问题.txt

[20190419]bash单双引号问题.txt

原创 Linux操作系统 作者:lfree 时间:2019-04-22 09:31:58 0 删除 编辑

[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/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    2409
  • 访问量
    6177710