- 论坛徽章:
- 0
|
shell 在传递参数中带单引号时,会将' 转换成'\''。这样有的程序就会将'\''直接当作参数处理了,使程序出现错误。
./tt.sh "-a '/export/home/bin/lserver' -w 1:1 -c 1:1"
+ cmd=/usr/local/nagios/libexec/check_procs
+ params='-a '\''/export/home/pcs/bin/lserver'\'' -w 1:1 -c 1:1'
++ ./t1.sh -a ''\''/export/home/bin/lserver'\''' -w 1:1 -c 1:1
+ echo '$1:-a'
+ echo '$2:'\''/export/home/bin/lserver'\'''
+ echo '$3:-w'
+ echo '$4:1:1'
+ echo '$5:-c'
+ echo '$6:1:1'
+ result='$1:-a
$2:'\''/export/home/bin/lserver'\''
$3:-w
$4:1:1
$5:-c
$6:1:1'
+ echo '$1:-a' '$2:'\''/export/home/bin/lserver'\''' '$3:-w' '$4:1:1' '$5:-c' '$6:1:1'
$1:-a $2:'/export/home/bin/lserver' $3:-w $4:1:1 $5:-c $6:1:1
执行出错的程序
./tt.sh "-a '/sbin/mingetty tty3' -w 1:1 -c 1:1"
+ cmd=/usr/local/nagios/libexec/check_procs
+ params='-a '\''/sbin/mingetty tty3'\'' -w 1:1 -c 1:1'
++ /usr/local/nagios/libexec/check_procs -a ''\''/sbin/mingetty' 'tty3'\''' -w 1:1 -c 1:1
+ result='PROCS CRITICAL: 0 processes with args '\'''\''/sbin/mingetty'\'', STATE = tty3'\'''
+ echo PROCS CRITICAL: 0 processes with args ''\'''\''/sbin/mingetty'\'',' STATE = 'tty3'\'''
PROCS CRITICAL: 0 processes with args ''/sbin/mingetty', STATE = tty3'
|
|