假設我有一個接受兩個引數的 python 腳本:
python3 a.py '/001/001.txt' '/after/001'
'/001/001.txt' 將是輸入檔案路徑,'/after/001' 將是輸出路徑,我想知道如何在以下 bash 命令中設定 input_path 和 output_path 以自動回圈檔案001 至 909。
i=1;
while [ $i -le 909 ];
do
input_path = ''
output_path = '';
python3 a.py $input_path $output_path
i=$((i 1));
done
我是第一次使用 bash 命令,所以有人可以分享如何解決這個問題嗎?太感謝了
uj5u.com熱心網友回復:
版本bash>= 4.0:
for i in {001..909}; do
echo python3 a.py "/$i/$i.txt" "/after/$i"
done
版本bash>= 3.1:
for ((i=1; i<=909; i )); do
printf -v x "d" "$i"
echo python3 a.py "/$x/$x.txt" "/after/$x"
done
如果輸出看起來不錯,請洗掉echo.
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/447739.html
