Thursday, February 3, 2022

[SOLVED] setting result's and operand's default value in bash

Issue

bash 4.2

the equation
i=$(( (i+1) %3 ))

I want left i to be 0 when the right i is wrong input like null.

something like i=${((i+3) %3):=0} if I can.


Solution

Let's try with:

i=$(( ( ${i-0} + 1) %3 ))



Answered By - Antonio Petricca
Answer Checked By - Mary Flores (WPSolving Volunteer)