2014-12-08 49 views
0
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 只是过程的图像尺寸,因此引入了可变折射率地图我的变量的指标......但无法得到它的窍门。它给出了一个错误。我想在bash

+0

'IFS = X读取宽度高度<<<“$ IMAGE_SIZE”'应努力设置这些变量,虽然你想验证之前'bash' 4.3 ,当为这条字符串读取的命令设置'IFS'时修正了一些错误。 – chepner 2014-12-08 14:44:59

回答

1

那里有一些语法错误。我注释他们的意见:

#!/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 
+0

C样式for循环中的变量被视为算术表达式,所以'index <$ {#FList [@]}'可以正常工作。 – chepner 2014-12-08 14:43:15

+0

哦,你是对的。这很有趣,因为它提供了一种排序的指针变量。我的意思是像'var = i; for(($ var = 0; $ var <10; ++ $ var)){echo $ i; }'。无论如何,我最好在答案中解决这个问题。谢谢! – Wintermute 2014-12-08 15:01:20

+0

你可能实际上不想写这样的代码,虽然:) – chepner 2014-12-08 15:12:02