测试习惯的方法,如果没有位置PARAMS给出? [英] Idiomatic way to test if no positional params are given?

查看:165
本文介绍了测试习惯的方法,如果没有位置PARAMS给出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是bash中最惯用的方式来测试,如果没有位置给定参数?有这么多的方法来检查这一点,我不知道是否有一个preferred方式。

有些方法是:

 ((!$#))#检查$#是不正确的
(($#== 0))#$#0
[! $ @]#$ @是设置或者为空


解决方案

对于我来说,传统的方法是:

  [$#-eq 0]

What is the most idiomatic way in Bash to test if no positional parameters are given? There are so many ways to check this, I wonder if there is one preferred way.

Some ways are:

((! $# )) # check if $# is 'not true'
(($# == 0)) # $# is 0
[[ ! $@ ]] # $@ is unset or null

解决方案

For me, the classical way is:

[[ $# -eq 0 ]]

这篇关于测试习惯的方法,如果没有位置PARAMS给出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆