one line definition of a variable conditional on the output of a logical test
0
votes
1
answer
746
views
In
bash
programming I've always defined conditional variables in the following long hand way
dog=1
if [[ $dog -eq 1 ]] ; then
cow=1
else
cow=0
fi
This is obviously incredibly inefficient. In MATLAB
I can do the following
cow=(dog==1)
i.e., one line instead of five. Is there an analogous way to do this in bash? Thanks for any advice.
Asked by Leo Simon
(453 rep)
Aug 21, 2020, 06:01 PM
Last activity: Aug 22, 2020, 12:32 AM
Last activity: Aug 22, 2020, 12:32 AM