Search code examples
bashunixdatastage

How to save the if then else output in a variable unix


I have a variable(stageVar) getting from Datastage, and need to check whether that variable is equal to zero then replace the 100 else stageVar. After that I need to find the mod and save in variable.

I have tried the below code but am not successful.

var= if [stageVar -eq 0] ; then "100" ; else stageVar ; fi; var2='expr $var % 100'; echo $var2;

Solution

  • You can use this in bash:

    [[ $stageVar -eq 0 ]] && var=100 || var=$stageVar
    ((var2 = var % 100))
    echo $var2