+ -
当前位置:首页 → 问答吧 → shell 定义数组问题

shell 定义数组问题

时间:2011-06-24

来源:互联网

在HP Unix 中碰到这样的一个问题
etl1$ set -A test 20 30
etl1$ echo ${test[@]}
20 30
etl1$ set -A test -20 30
sh: -20: A specified flag is not valid for this command.

为什么在数组定义中,如果第一个为负数就报错?

作者: roman924   发布时间: 2011-06-24

-被当成命令行参数了吧。一般是用--转义下。比如:
set -A -- test -20 30
或者
set -A test -- -20 30
具体怎么写不确定,手头没你这个shell。你自己试试吧。

作者: iambic   发布时间: 2011-06-24