Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在linux shell中如何检查数字是否为偶数?_Linux - Fatal编程技术网

在linux shell中如何检查数字是否为偶数?

在linux shell中如何检查数字是否为偶数?,linux,Linux,我试过了 我要一行命令 pancmite@atlas:~$ test ($LSD / 2) -eq 0 bash: syntax error near unexpected token `$LSD' pancmite@atlas:~$ test $LSD / 2 -eq 0 bash: test: too many arguments pancmite@atlas:~$ test $number -lt $LSD bash: test: -lt: unary operator expecte

我试过了

我要一行命令

pancmite@atlas:~$ test ($LSD / 2) -eq 0
bash: syntax error near unexpected token `$LSD'

pancmite@atlas:~$ test $LSD / 2 -eq 0
bash: test: too many arguments

pancmite@atlas:~$ test $number -lt $LSD
bash: test: -lt: unary operator expected
或者:

expr $LSD % 2
返回值1为奇数,0为偶数。所以你可以试着做个测试:

$((LSD % 2))

您应该得到一个返回值1。

@Terminator不要忘记接受答案。答案旁边有一个复选标记的轮廓。
LSD=5
echo $((LSD % 2))