在linux中找到最重要的位

时间:2016-07-07 06:11:34

标签: linux shell

我正在使用raspberry pi,命令:

char-write-req 0x0011 e00000e0

我得到ouput1

12 57 7e 35 2d 49

类似地,

char-write-req 0x0011 e00100e1

output2是:

23 45 76 3e 66 2d

以类似的方式我得到不同命令的输出,现在我想检查MSB并在交换机情况下传递该位,即我想要" 1"来自ouput1的12和" 2"从output2的23开始,为此生成一个切换案例。 我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

使用cut -c 1从输出中获取第一个字符:

char-write-req 0x0011 e00000e0 | cut -c 1

对于您使用的案例:

case `char-write-req 0x0011 e00000e0 | cut -c 1` in                               
    1) echo "something" ;;                                                      
    2) echo "something else" ;;                                                 
esac
相关问题