所以我查看了while循环的示例并将脚本放在一起,但仍然存在问题。如果我猜测我会用bc函数的算术部分说出来。
我希望循环运行直到我达到一千,然后计算它运行了多少次。我不是要编写脚本的计数部分,因为我仍然只是想让它运行(是的,我知道awk会更容易)。
这是我到目前为止所做的:
#!/bin/bash
total=120 #this will be a variable that is read in from a menu but 120 is ok for now
while [ $total -lt 1000000 ]
do
echo $total
total=$(bc<<<"scale=2;$total + $total * .1") #I don't know if I have to use "let" before total but it did not make a difference.
done.
我收到以&#34; total&#34;开头的行的错误但命令的结构似乎适合我能找到的所有例子。是什么给了什么?
答案 0 :(得分:3)
使用bc
进行比较。
#!/usr/bin/env bash
total=120
while [ "$(bc <<< "$total < 1000000")" == 1 ]
do
echo $total
total=$(bc <<< "scale=2;$total + $total * .1")
done
答案 1 :(得分:0)
只要处理整数,就可以使用算术表达式def mutual_info_classif_custom(X, y):
# To change discrete_features,
# you need to redefine the function each time
# Because once the func def is supplied to selectKBest, it cant be changed
discrete_features = [0, 1, 2]
return mutual_info_classif(X, y, discrete_features)
编写循环,而不需要像selector = SelectKBest(mutual_info_classif_custom).fit(X, y)
这样的外部命令:
(( ... ))