当前位置: 技术问答>linux和unix
shell脚本里判断条件如何用“或”连接?
来源: 互联网 发布时间:2017-05-15
本文导语: for testjob in rand-read rand-write seq-read seq-write do { echo ${testjob} if [ "${testjob}"="rand-read" ]||[ "${testjob}"="seq-read" ]; then word="read : io" else ...
for testjob in rand-read rand-write seq-read seq-write
do
{
echo ${testjob}
if [ "${testjob}"="rand-read" ]||[ "${testjob}"="seq-read" ];
then
word="read : io"
else
word="write: io"
fi
echo ${word}
}
done
上面的这段脚本为什么每次word 的值都是read :io ,根本不执行else部分的语句??。。。谢谢大家
|
if [ "${testjob}" = "rand-read" -o "${testjob}" = "seq-read" ];
等号前后要空格
等号前后要空格
|
#!/bin/bash
for testjob in rand-read rand-write seq-read seq-write; do
echo ${testjob}
if [ "${testjob}" = "rand-read" -o "${testjob}" = "seq-read" ]; then
word="read : io"
else
word="write: io"
fi
echo ${word}
done