2016-01-07 186 views
0

我想讀的bash腳本bash腳本讀取輸入

test.sh input1 id1 name1 input2 id2 name2 input3 id3 name3 

我想讀的輸入迴路和分配的三個參數組,局部變量和運行不同的命令如

for var in "[email protected]" 
    do 
    input=$var 
    id=$var+1 
    name=$var+2 
    rawFastq=${input} 
    echo "input is" $input 
    echo "id" $id 
    echo "name is" $name 
    Rscript "$input"/script1.R ID name 

done 

如何進入下一個命令行參數。 $var+1或添加計數器,然後做${i+1}不起作用?

+0

什麼不起作用? –

+0

「get next cmd-line param」with'shift'。祝你好運。 – shellter

回答

0

您必須迭代用戶參數的元素,就像在任何其他編程語言中一樣。例如:

args=("[email protected]") 
i=0 
while [ $i -lt ${#args[@]} ]; do 
    input=${args[$i]} 
    i=$[$i+1] 
    id=${args[$i]} 
    i=$[$i+1] 
    name=${args[$i]} 
    i=$[$i+1] 

    Rscript $input/script1.R $id $name 
done 
+0

It works ..非常感謝你:) – user5758172