Check Odd or Even Numbers in Linux

In a Linux system, you can use a shell script to input a number and determine if it is odd or even. Here is a simple example of a shell script:

#!/bin/bash

echo "请输入一个数字:"
read num

if [ $((num % 2)) -eq 0 ]; then
    echo "$num 是偶数"
else
    echo "$num 是奇数"
fi

Save the above code as a .sh file (for example, odd_even.sh), then run the script in the terminal. Follow the prompt to input a number and determine if it is odd or even.

bannerAds