【发布时间】:2014-07-15 15:34:21
【问题描述】:
我正在尝试完成以下结果
给定一个使用以下参数执行的 bash 脚本
#Input
./xxx.sh "\\\"P1\\\"\\\"P2\\\"\\\"P3\\\"\\\"P4\\\"\\\"P5\\\""
我要去掉第五个参数
#Output
# "\\\"P1\\\"\\\"P2\\\"\\\"P3\\\"\\\"P4\\\""
不管第五个参数是空\\\"\\\"还是不\\\"P5\\\"
我做了下面的脚本,但只有在最后一个参数为空时才会删除。如果我也需要删除第四个第三个参数,例如,我该如何继续?
a=$*
b=` echo $a | sed 's/[\\"[:alnum:]\\"]*$//g' `
b=` echo $a | sed 's/[\\"*\\"]*$//g' `
#the last try bellow give me the reasonable result when the fifth param is empty
b=` echo $a | sed 's/[\\"\\"]*$//g' `
echo $b
对不起,我到现在还是个壳佬
我在 ksh shell 中遇到了问题,但这有效
b=` echo $a | sed -e 's/\\\\"[^"]*\\\\"$//g' `
谢谢大家
【问题讨论】: