gpt4 book ai didi

linux - 我想在 bash 中映射变量的索引

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

NList=(5)
VList=(1)
FList=("input/flower1.jpg" "input/flower2.jpg" "input/flower3.jpg" "input/flower4.jpg")
IList=("320X240" "640X480" "1280X960" "1920X1200")
SList=(2 3)
for VM in ${VList[@]}; do

for ((index=0; index < ${#FList};)) do
file=$FList[$index]
image_size=$IList[$index]
width=`echo $image_size|cut -d "X" -f1`
height=`echo $image_size|cut -d "X" -f2`
for scale_factor in ${SList[@]}; do
for users in ${NList[@]}; do
echo "V: $VM, " "F: $file, " "S: $scale_factor, " "I: $width $height , " "N: $users"
for i in `seq 1 $users` ; do
./sr_run_once.sh $file $width $height $scale_factor &
done
wait
done # for users
done # for scale_factor
done # for index
done # for VM
exit 0

我希望 Flistsay flower1 应该只处理 320*240 的图像大小因此引入了变量索引......但无法掌握它。它给出了一个错误。

最佳答案

其中有一些语法错误。我在评论中对它们进行了注释:

#!/bin/bash
# ^-- shebang for bash because you use bash extensions.

NList=(5)
VList=(1)
FList=("input/flower1.jpg" "input/flower2.jpg" "input/flower3.jpg" "input/flower4.jpg")
IList=("320X240" "640X480" "1280X960" "1920X1200")
SList=(2 3)

for VM in ${VList[@]}; do
# +-- You've used the right syntax above, you have
# | to use it here as well.
# |
# | +--- and here you have to increment
# v v the index to move forward.
for ((index=0; $index < ${#FList[@]}; ++index)) do

# v--- the braces here are not optional.
file=${FList[$index]}
image_size=${IList[$index]}
width=`echo $image_size|cut -d "X" -f1`
height=`echo $image_size|cut -d "X" -f2`
for scale_factor in ${SList[@]}; do
for users in ${NList[@]}; do
echo "V: $VM, " "F: $file, " "S: $scale_factor, " "I: $width $height , " "N: $users"
for i in `seq 1 $users` ; do
./sr_run_once.sh $file $width $height $scale_factor &
done
wait
done # for users
done # for scale_factor
done # for index
done # for VM
exit 0

关于linux - 我想在 bash 中映射变量的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27354807/

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