我有这个简单的脚本来打印它收到的内容然后退出:
IFS="|${IFS}";
echo "$# parameters";
echo Using '$*';
for p in $*;
do
echo "[$p]";
done;
echo Using '"$*"';
for p in "$*";
do
echo "[$p]";
done;
echo Using '$@';
for p in $@;
do
echo "[$p]";
done;
echo Using '"$@"';
for p in "$@";
do
echo "[$p]";
done
如果我执行:./echoparams This is a "test target"
它将打印出:
4 parameters
Using $*
[This]
[is]
[a]
[Test]
[target]
Using "$*"
[This|is|a|Test target]
Using $@
[This]
[is]
[a]
[Test]
[target]
Using "$@"
[This]
[is]
[a]
[Test target]
问题:
我有一个外部程序(我无法修改)将它传递到我的脚本中,但是当它执行时它会打印出这个:
1 parameters
Using $*
[This]
[is]
[a]
["test]
[target"]
Using "$*"
[This is a "test target"]
Using $@
[This]
[is]
[a]
["test]
[target"]
Using "$@"
[This is a "test target"]
我有一种预感,它实际上正在传递"This is a \"test target\""
到脚本中。 我怎样才能把这个“一个参数”变成“多个参数”,但仍然尊重组合词(用引号括起来)?