gpt4 book ai didi

linux - 如何在 Bash 中运行多次相同的代码

转载 作者:太空宇宙 更新时间:2023-11-04 13:04:47 25 4
gpt4 key购买 nike

如何多次运行同一代码?比如12次?

 sed -n 1,1p 00-02.txt | sed -e 's/^/<video length="-1" src="mp4:/' \
-e 's/$/" start="0"><\/video>/' >>playlist.txt

echo -e "$(sed -e '1,1d' 00-02.txt)\n" > 00-02.txt

cat 00-02.txt | sed '/^$/d' >> 00-02a.txt

rm 00-02.txt

mv 00-02a.txt 00-02.txt

sed -n 1,1p spot.txt | sed -e 's/^/<video length="-1" src="mp4:/' \
-e 's/$/" start="0"><\/video>/' >>playlist.txt

echo -e "$(sed -e '1,1d' spot.txt)\n" > spot.txt

cat spot.txt | sed '/^$/d' >> spota.txt

rm spot.txt

mv spota.txt spot.txt

所有爱的代码必须复制N次

有点像

for n in {1..12}; **ALL THE COMMANDS BELOVE**; done

但它不适用于多行命令。

有什么问题吗?

最佳答案

使用 while 循环和计数器:

#!/bin/bash

iterations=12
count=0

while [ "$count" -lt "$iterations" ]
do
sed -n 1,1p 00-02.txt | sed -e 's/^/<video length="-1" src="mp4:/' \
-e 's/$/" start="0"><\/video>/' >>playlist.txt

echo -e "$(sed -e '1,1d' 00-02.txt)\n" > 00-02.txt

cat 00-02.txt | sed '/^$/d' >> 00-02a.txt

rm 00-02.txt

mv 00-02a.txt 00-02.txt

sed -n 1,1p spot.txt | sed -e 's/^/<video length="-1" src="mp4:/' \
-e 's/$/" start="0"><\/video>/' >>playlist.txt

echo -e "$(sed -e '1,1d' spot.txt)\n" > spot.txt

cat spot.txt | sed '/^$/d' >> spota.txt

rm spot.txt

mv spota.txt spot.txt
count=$(( count + 1 ))
done

关于linux - 如何在 Bash 中运行多次相同的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32980736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com