How to build a conditional assignment in bash?

后端 未结 8 2024
慢半拍i
慢半拍i 2021-01-31 01:04

I\'m looking a way to build conditional assignments in bash:

In Java it looks like this:

int variable= (condition) ? 1 : 0;
8条回答
  •  鱼传尺愫
    2021-01-31 01:43

    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.

提交回复
热议问题