如何建立在bash条件分配? [英] How to build a conditional assignment in bash?
本文介绍了如何建立在bash条件分配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种方式来建立有条件的任务在bash:
在Java中,它看起来是这样的:
int变量=(条件)? 1:0;
解决方案
根据乔纳森的评论:
变量= $((1 == 1?1:0))
编辑:
我修改了原来的答复刚刚回声
倒是条件运算符的价值,它实际上并没有表现出任何的分配。的
I'm looking a way to build conditional assignments in bash:
In Java it looks like this:
int variable= (condition) ? 1 : 0;
解决方案
As per Jonathan's comment:
variable=$(( 1 == 1 ? 1 : 0 ))
EDIT:
I revised the original answer which just echo
'd the value of the condition operator, it didn't actually show any assignment.
这篇关于如何建立在bash条件分配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文