我有以下bash代码,并希望将字符串转换为命令行参数以传递给其他程序。
所以我有GETVARS,想分开并做一些像
这样的事情./ somecommand $ GETVARS [0] $ GETVARS [1]
等等
GETVARS将是任意长度的元素。
GETVARS = ""
for id in {100..500..10}
do
for letter in A B C D E F
do
GETVARS=$GETVARS"\":${id}:${letter}\" "
done
done
//GETVARS = "":100:A" "100:B" "100:C"" .. and so on
答案 0 :(得分:0)
从
开始getvars="" # no spaces around commas, use smaller case variable names
根据要求,您显然正在寻找像
这样的简单数组getvars=() # or do declare -a getvars
我不清楚这个要求,但下面就是我想你应该做的事情
for id in {100..500..10}
do
for letter in A B C D E F
do
getvars+=( \":${id}:${letter}\" ) # adding elements to array
done
done
#and later do the following
./somecommand "${getvars[@]}" # Each element will be separated to a word