CSH 集团存在性测试与价值测试
在 CSH 中,是否可以将变量是否存在的测试与其值的测试嵌套在同一个 if 子句中?
#!/bin/csh
# This seems to work...
if ( $?VAR ) then
echo "VAR exists"
if ( $VAR == true ) then
echo "VAR is true"
endif
endif
# I want something more like this:
if (( $?VAR ) && ( $VAR == true )) then
echo "VAR exists and is true"
endif
In CSH, is it possible to nest the test for an existance of a variable with the test for its value in the same if-clause?
#!/bin/csh
# This seems to work...
if ( $?VAR ) then
echo "VAR exists"
if ( $VAR == true ) then
echo "VAR is true"
endif
endif
# I want something more like this:
if (( $?VAR ) && ( $VAR == true )) then
echo "VAR exists and is true"
endif
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
短路评估是 C shell 不具备的许多功能之一做。您必须使用嵌套的
if
语句或 switch shell。Short-circuit evaluation is one of the many things that C shell doesn't do. You will have to use nested
if
statements or switch shells.