How to build a conditional assignment in bash?

后端 未结 8 2026
慢半拍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:50

    If you want a way to define defaults in a shell script, use code like this:

    : ${VAR:="default"}
    

    Yes, the line begins with ':'. I use this in shell scripts so I can override variables in ENV, or use the default.

    This is related because this is my most common use case for that kind of logic. ;]

提交回复
热议问题