Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 仅为一行中的5个文件触发循环_Bash_Shell - Fatal编程技术网

Bash 仅为一行中的5个文件触发循环

Bash 仅为一行中的5个文件触发循环,bash,shell,Bash,Shell,我正在尝试用几个html文件创建一个html,但这不是我的问题,因为这样做很好。问题是,到目前为止我编写的代码是将多个html文件写入一个html,但我只想将5个html合并成一个。如果将生成的一个html文件包含5个以上的html文件,那么它应该创建一个新的html文件,然后一个…获取它?创建一个计数变量,在循环中递增它,并在达到5后使用break语句中断 请参见:创建一个计数变量,在循环中增加它,并在达到5后使用break语句中断 请参见:这假设您需要t1.html、t2.html等 idx

我正在尝试用几个html文件创建一个html,但这不是我的问题,因为这样做很好。问题是,到目前为止我编写的代码是将多个html文件写入一个html,但我只想将5个html合并成一个。如果将生成的一个html文件包含5个以上的html文件,那么它应该创建一个新的html文件,然后一个…获取它?

创建一个计数变量,在循环中递增它,并在达到5后使用
break
语句中断


请参见:

创建一个计数变量,在循环中增加它,并在达到5后使用
break
语句中断


请参见:

这假设您需要t1.html、t2.html等

idx=0
counter=0
target=
for file in *; do
    if [ $((counter%5)) -eq 0 ]; then
        idx=$((idx+1))
        target=t${idx}.html
    fi
    # write to $target
    counter=$((counter+1))
done

这假设您需要t1.html、t2.html等

idx=0
counter=0
target=
for file in *; do
    if [ $((counter%5)) -eq 0 ]; then
        idx=$((idx+1))
        target=t${idx}.html
    fi
    # write to $target
    counter=$((counter+1))
done

我没有一个实用的解决方案,但是为什么不在循环中添加一个计数器呢?然后,如果计数器达到5,请使用文件夹中接下来5个文件的内容创建一个新文件。我没有实际的解决方案,但为什么不在循环中添加一个计数器呢?然后,如果计数器达到5,则使用文件夹中接下来5个文件的内容创建一个新文件。