Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
688 views
in Technique[技术] by (71.8m points)

bash - How do I check whether a variable has an even numeric value?

How should I change this to check whether val has an even or odd numeric value?

val=2
if $((RANDOM % $val)); ...
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
$ a=4

$ [ $((a%2)) -eq 0 ] && echo "even"
even

$ a=3

$ [ $((a%2)) -eq 0 ] && echo "even"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...