2014-12-08 60 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