如何使用uboot测试命令'or' -o选项
How to use uboot test command 'or' -o option
从下面的输出来看,该命令似乎不适用于整数或 true 和 false 命令,那么 test -o
(或)命令的预期用途是什么?
=> version
U-Boot 2017.01 (Apr 01 2021 - 00:00:00 +0000)
arm-poky-linux-gnueabi-gcc (GCC) 9.3.0
GNU ld (GNU Binutils) 2.34.0.20200220
=> if test 0 -o 0; then echo yeehaw; else echo yeenaw; fi
yeehaw
=> if test 1 -o 0; then echo yeehaw; else echo yeenaw; fi
yeehaw
=> if test 0 -o 1; then echo yeehaw; else echo yeenaw; fi
yeehaw
=> if test 0 -o 0; then echo yeehaw; else echo yeenaw; fi
yeehaw
=> if test 1 -o 1; then echo yeehaw; else echo yeenaw; fi
yeehaw
=> if test false -o false; then echo yeehaw; else echo yeenaw; fi
yeehaw
=> if test true -o false; then echo yeehaw; else echo yeenaw; fi
yeehaw
=> if test false -o true; then echo yeehaw; else echo yeenaw; fi
yeehaw
=> if test true -o true; then echo yeehaw; else echo yeenaw; fi
yeehaw
如果字符串为 non-empty,则认为该字符串为真,如果为空则为假:
$ if test ""; then echo true; else echo false; fi
false
$ if test "x"; then echo true; else echo false; fi
true
因此test "" -o x
为真。您还可以在更复杂的比较之间使用 -o
:
# Make sure 0 < $x < 10
if test "$x" -le 0 -o "$x" -ge 10; then echo "out of range"; fi
但是,POSIX 建议使用可移植的 shell 构造 ||
而不是依赖旧运算符 test -o
。
从下面的输出来看,该命令似乎不适用于整数或 true 和 false 命令,那么 test -o
(或)命令的预期用途是什么?
=> version
U-Boot 2017.01 (Apr 01 2021 - 00:00:00 +0000)
arm-poky-linux-gnueabi-gcc (GCC) 9.3.0
GNU ld (GNU Binutils) 2.34.0.20200220
=> if test 0 -o 0; then echo yeehaw; else echo yeenaw; fi
yeehaw
=> if test 1 -o 0; then echo yeehaw; else echo yeenaw; fi
yeehaw
=> if test 0 -o 1; then echo yeehaw; else echo yeenaw; fi
yeehaw
=> if test 0 -o 0; then echo yeehaw; else echo yeenaw; fi
yeehaw
=> if test 1 -o 1; then echo yeehaw; else echo yeenaw; fi
yeehaw
=> if test false -o false; then echo yeehaw; else echo yeenaw; fi
yeehaw
=> if test true -o false; then echo yeehaw; else echo yeenaw; fi
yeehaw
=> if test false -o true; then echo yeehaw; else echo yeenaw; fi
yeehaw
=> if test true -o true; then echo yeehaw; else echo yeenaw; fi
yeehaw
如果字符串为 non-empty,则认为该字符串为真,如果为空则为假:
$ if test ""; then echo true; else echo false; fi
false
$ if test "x"; then echo true; else echo false; fi
true
因此test "" -o x
为真。您还可以在更复杂的比较之间使用 -o
:
# Make sure 0 < $x < 10
if test "$x" -le 0 -o "$x" -ge 10; then echo "out of range"; fi
但是,POSIX 建议使用可移植的 shell 构造 ||
而不是依赖旧运算符 test -o
。