所以我想根据变量的数量创建x个目录。在bash中使用for循环创建目录
#!/bin/bash
countOfCaptureFiles=$(wc -l < allCaptures.txt)
echo $countOfCaptureFiles
start=1
end=countOfCaptureFiles
for((i=$start;i<=$end;i++))
do
mkdir "SnortAlert${i}"
done
在我目前的测试环境countOfCaptureFiles的值是3,所以我希望创建3个目录名为SnortAlert1 SnortAlert2 SnortAlert3。
我像下面这样运行该脚本:./myscript.sh
但是我这样做,我得到的错误,并没有输出时,我相信这是与assinging结束= countOfCaptureFiles但我不知道如何要解决这个问题,任何帮助将不胜感激!
代码你缺少一个'$'='分配。让它结束'= $ countOfCaptureFiles'。 – codeforester
我已经在我的mac上测试了你的代码没有问题$是可选的,因为i <= $ end被评估为i <= countOfCaptureFiles并且再次被评估为i <= 3什么是错误信息?你是否chmod + x myscript .sh'? – thatseeyou
您可以从排序的角度出发,让您在末尾添加固定宽度的所有整数,例如'001,002,003,...',您可以使用'printf -v name'SnortAlert%03d “”$ i“',然后是”mkdir“$ name”' –