bash:迭代浮点数列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11902284/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 02:58:29  来源:igfitidea点击:

bash: iterate over list of floating numbers

bashfor-loopfloating-point

提问by Ricky Robinson

In bash script, I want to iterate over a list of values that I want to pass as parameters to a script in python. It turns out that $dand $minFreqaren't floats when passed to the python script. Why does this happen?

在 bash 脚本中,我想遍历要作为参数传递给 python 脚本的值列表。事实证明,$d$minFreq传递给python脚本时不浮动。为什么会发生这种情况?

for d in {0.01, 0.05, 0.1}
do
    for i in {1..3}
    do
        someString=`python scrpt1.py -f myfile --delta $d --counter $i| tail -1`
        for minFreq in {0.01, 0.02}
        do
            for bValue in {10..12}
            do
                python testNEW.py $someString -d $bValue $minFreq
            done
        done
    done
done

回答by chepner

Either remove the spaces

要么删除空格

for d in {0.01,0.05,0.1}

or don't use the {} expansion (it's not necessary here):

或者不使用 {} 扩展(这里没有必要):

for d in 0.01 0.05 0.1

The same applies to the minFreqloop.

这同样适用于minFreq循环。



As written,

正如所写,

for d in {0.01, 0.05, 0.1}

the variable dis assigned the literal string values {0.01,, 0.05,, and 0.1}.

变量d被分配了文字串的值{0.01,0.05,0.1}