- 论坛徽章:
- 0
|
通过shell教本给java传参数,总是被空格断开(我的目的是接受带空格的参数
)
[code]#!/usr/bin/ksh
#
PARAMS="";
while getopts dek:f:t:vh OPTION
do
case $OPTION in
d | e | v | h)
PARAMS=$PARAMS" -$OPTION"
;;
k)
PARAMS=$PARAMS" -k$OPTARG";
;;
f | t)
PARAMS=$PARAMS" "\""-"$OPTION$OPTARG\";
;;
\?)echo "Illegal Paremters"
exit 1;;
esac
done
echo $PARAMS
#$JAVA_HOME/bin/java MyTEST $PARAMS
MyTEST{
public static void main(String args[])
{
...
for (int i = 0; i < args.length; i++) {
if (args[i].startsWith("-d"))
dec = true;
else if (args[i].startsWith("-e"))
enc = true;
else if (args[i].startsWith("-f"))
file_name = args[i].substring(2, args[i].length());
else if (args[i].startsWith("-k"))
key = args[i].substring(2, args[i].length());
else if (args[i].startsWith("-t"))
text = args[i].substring(2, args[i].length());
else if (args[i].startsWith("-a"))
algorithm = args[i].substring(2, args[i].length());
else if (args[i].startsWith("-v"))
verbose = true;
else if (args[i].startsWith("-h"))
usage();
else
System.out.println("Unknow args:" + args[i]);
}
...
}
}[/code]
运行shell脚本 给参数 "abc 00", java接受到两个参数 "abc和00"
怎么回事? |
|