检查 KSH 脚本参数的数量
当使用以下参数执行 myscript
时,它会失败并显示错误 255(如下)
1 2 3 4 5 6 7
myscript value value /my/path/to/file my_file /tmp/ value value
检查传递参数的数量
if [ ${#} -ne 7 ]
echo ${#} // Actually prints 7
then
echo "ERROR 255: Must provide the following 7 parameters:
one two three four five six seven"
exit 255
fi
所以...如果数字不是 7,则退出,但请告诉数字是多少... 7.
世界疯了吗? :)
When myscript
is executed with the following arguments it fails with error 255 (below)
1 2 3 4 5 6 7
myscript value value /my/path/to/file my_file /tmp/ value value
Checking number of passed arguments
if [ ${#} -ne 7 ]
echo ${#} // Actually prints 7
then
echo "ERROR 255: Must provide the following 7 parameters:
one two three four five six seven"
exit 255
fi
So ... If the number is not 7, exit, but do tell what the number is .. 7.
Has the world gone mad? :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你确定你的问题没有错别字吗?
在
if [ ... ]
和then
之间添加echo ${#}
是一个语法错误,会让我的 ksh 崩溃向上;-) 否则我认为你的代码看起来是正确的。但为什么不使用更新的 ksh 数学评估功能(也许这会解决您的问题)。
我希望这有帮助。
Are you sure you don't have a typo in your question?
Having the
echo ${#}
in between theif [ ... ]
and thethen
is a syntax error, and makes my ksh blow up ;-) Otherwise I think your code looks correct.But why not use newer ksh math evaluation features (maybe this will fix your problem).
I hope this helps.