user3530026
user3530026

Reputation:

Get an element of a list inside a command in SHELL script

I would like to run a Java application with specified parameter settings, and some of the parameters will come from an iteration of a list. This could be the proper way? Many Thanks!

outs="/home/user/this.vcf /home/user/that.vcf  /home/user/simulation/control.vcf"
arr=($outs)

ending=3

for ((i=1;i<=ending;i++)); do
java -Xmx32g -jar /home/user/something.jar \
-o $arr[i] \
done

Upvotes: 0

Views: 95

Answers (2)

anubhava
anubhava

Reputation: 785108

You don't need to hardcode count. Just iterate the array like this:

outs=( "/home/user/this.vcf" "/home/user/that.vcf" "/home/user/simulation/control.vcf" )

for word in "${outs[@]}"; do
   java -Xmx32g -jar /home/user/something.jar -o "$word"
done

Upvotes: 1

Mureinik
Mureinik

Reputation: 311198

You are missing brackets. Additionally, note that shell arrays are zero-based, so your for statement needs to be amended:

for ((i=0;i<ending;i++)); do
java -Xmx32g -jar /home/user/something.jar \
-o ${arr[i]} \
done

Upvotes: 0

Related Questions