我有1.txt 2.txt和script.php
1.txt: a b c d 2.txt www rrr ttt yyy
我希望bash文件在Linux下执行这个命令:
./script.php -na -j www>>n_j.txt ./script.php -na -j rrr>>n_j.txt ./script.php -na -j ttt>>n_j.txt ./script.php -na -j yyy>>n_j.txt ./script.php -nb -j www>>n_j.txt ./script.php -nb -j rrr>>n_j.txt ./script.php -nb -j ttt>>n_j.txt . .
我有一个蝙蝠代码与wondows cmd工作..我想要一个代码,它可以使用Linux命令行
@ECHO OFF FOR /F "tokens=1 delims= " %%I IN (1.txt) DO FOR /F "tokens=1 delims= " %%E IN (2.txt) DO echo %%I %%E>n_j.txt & echo name_job: %%I %%E & FOR /F "tokens=*" %%S IN ('script.php -n %%I -j %%E') DO echo %%S>>names\n_j.txt
#!/bin/bash arr1="" arr2="" mapfile -t arr1 <1.txt mapfile -t arr2 <2.txt for i in ${!arr1[@]}; do for j in ${!arr2[@]}; do ./script.php -n "${arr1[i]}" -j "${arr2[j]}" >>n_j.txt done done
mapfile -t
将文件转换为数组,其中文件的每一行都是数组中的新索引(-t删除结尾的换行符)。 for循环遍历数组的每个索引,外循环遍历第一个文件中的行,内循环遍历第二个文件中的行,使用当前数组索引调用script.php。
只需在while循环中管道文件,看看这可以帮助。
#!/bin/bash while read arg1 do while read arg2 do ./script.php -n $arg1 -j $arg2 >>n_j.txt done<2.txt done<1.txt