bash - 在 bash 脚本中运行 if 语句时出错
问题描述
在这里,我编写了一个基本的 bash 脚本。我希望 if 块组织将输出写入的位置。我编写条件逻辑的方式是否存在语法错误?我得到的错误是针对我有 if 或 elif 语句的每一行。我相信这可能与 -eq 比较运算符有关,也可能与缺少或括号有关。
这是我遇到的错误的示例(终端中发生的最后一个错误;最接近底部):
./lit: line 17: [2: command not found
./lit: line 20: [2: command not found
./lit: line 23: [2: command not found
./lit:第 28 行:[3:找不到命令
./lit: line 31: [3: command not found
./lit: line 34: [3: command not found
./lit: line 37: [3: command not found
./lit:第 42 行:[3:找不到命令
./lit:第 45 行:[3:找不到命令
./lit:第 48 行:[3:找不到命令
./lit: line 51: [3: command not found
./lit: line 56: [3: command not found
./lit: line 59: [3: command not found
./lit: line 62: [3: command not found
./lit:第 65 行:[3:找不到命令
for i in {0..2};
do
for j in {0..3};
do
for k in {0..3}
do
for l in {0..3}
do
START=$(date +%s.%N)
#some command here
END=$(date +%s.%N)
DIFF=$(echo "$END - $START" | bc)
if ["$i" -eq "0"];
then
echo "test$i$j$k$l $DIFF" >> repeatSample.txt;
elif ["$i" -eq "1"]
then
echo "test$i$j$k$l $DIFF" >> writeZeroes.txt
elif ["$i" -eq "2"]
then
echo "test$i$j$k$l $DIFF" >> repeatPacket.txt
fi
if [$j -eq 0]
then
echo "test$i$j$k$l $DIFF" >> byte15.txt
elif [$j -eq 1]
then
echo "test$i$j$k$l $DIFF" >> byte100.txt
elif [$j -eq 2]
then
echo "test$i$j$k$l $DIFF" >> byte500.txt
elif [$j -eq 3]
then
echo "test$i$j$k$l $DIFF" >> byte1000.txt
fi
if [$k -eq 0]
then
echo "test$i$j$k$l $DIFF" >> loss10.txt
elif [$k -eq 1]
then
echo "test$i$j$k$l $DIFF" >> loss22.txt
elif [$k -eq 2]
then
echo "test$i$j$k$l $DIFF" >> loss37.txt
elif [$k -eq 3]
then
echo "test$i$j$k$l $DIFF" >> loss50.txt
fi
if [$l -eq 0]
then
echo "test$i$j$k$l $DIFF" >> pinkpanth.txt
elif [$l -eq 1]
then
echo "test$i$j$k$l $DIFF" >> poeee.txt
elif [$l -eq 2]
then
echo "test$i$j$k$l $DIFF" >> dooors.txt
elif [$l -eq 3]
then
echo "test$i$j$k$l $DIFF" >> simplehead.txt
fi
done
done
done
done
解决方案
推荐阅读
- snowflake-cloud-data-platform - 根据日期和在 Snowflake 中的另一个表中为该日期列出的最大行数限制插入到表中的行
- c++ - 如何从自定义向量中删除某些内容?C++
- amazon-s3 - 如何阻止 google-bot 索引我的 s3 存储桶中的文件夹?
- date - 如何使用 dtdate 格式计算 SAS 中的时间间隔
- java - 维护与服务器端服务的套接字连接对于向桌面应用程序发送通知是否不利?
- java - 仅在提交搜索后显示 Recyclerview
- python - 如何自定义pythonic损失函数并在keras中使用更长的y_true来计算?
- azure-timeseries-insights - 对复合时间序列 ID 建模
- c++ - 模板化概念作为 C++20 中的编译时接口
- php - 引导程序 4,列表组,搜索所有但显示有限行