使用案例中的Bash号范围 [英] Using Case for Range of Numbers in Bash
问题描述
我试图做使用CASE以下Bash中(在Linux中)
I am trying to do the following using CASE in Bash (In Linux)
如果X是460和660,输出x信息之间。
If X is between 460 and 660, output X information.
如果X是661和800之间,做别的事情。
If X is between 661 and 800, do something else.
等
现在这是我有:
case $MovieRes in
[461-660]*) echo "$MovieName,480p" >> moviefinal ;;
[661-890]*) echo "$MovieName,720p" >> moviefinal ;;
[891-1200]*) echo "$MovieName,1080p" >> moviefinal ;;
*) echo "$MovieName,DVD" >> moviefinal ;;
esac
但不知何故,许多包括480p,720p或1080p与DVD,而不是结束的几种。变量$ MovieRes是一个简单的列表,其中显示,每行1和1200之间的数字根据不同的值,CASE决定适用的案例。
But somehow many of the ones that are 480p, 720p or 1080p are ending with DVD instead. The variable $MovieRes is a simple list that shows, for each line, a number between 1 and 1200. Depending on the value, CASE decides which "case" to apply.
我想知道如何实际使用情况下做到这一点,因为它是与这样的范围打交道时有点混乱。
I would like to know how to actually use CASE to accomplish this since it is a bit confusing when dealing with ranges like this.
作为一个侧面说明,有关于如何使用情况下(bash)的教程任何网站也会有所帮助。
As a side note, any site that has tutorials on how to use CASE (In Bash) would help also.
推荐答案
在bash中,你可以使用算术EX pression
: ((...))
In bash, you can use the arithmetic expression
: ((...))
if ((461<=X && X<=660))
then
echo "480p"
elif ((661<=X && X<=890))
then
echo "720p"
elif ((891<=X && X<=1200))
then
echo "1080p"
else
echo "DVD"
fi >> moviefinal
这篇关于使用案例中的Bash号范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!