壳牌循环使用非整数? [英] Shell loops using non-integers?

查看:147
本文介绍了壳牌循环使用非整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个sh文件来编译和运行了家庭作业几个程序。我有为脚本循环,但它不会工作,除非我只用整数:

I wrote a .sh file to compile and run a few programs for a homework assignment. I have a "for" loop in the script, but it won't work unless I use only integers:

#!/bin/bash
for (( i=10; i<=100000; i+=100))
do
    ./hw3_2_2 $i
done

变量$ i为节目hw3_2_2输入,我有非整数值我想使用。我怎么能通过与十进制数的清单运行code循环?

The variable $i is an input for the program hw3_2_2, and I have non-integer values I'd like to use. How could I loop through running the code with a list of decimal numbers?

推荐答案

最简单的方法是只列出来:

The easiest way is to just list them:

for a in 1.2 3.4 3.11 402.12 4.2 2342.40
do
  ./hw3_2_2 $a
done

如果该列表是巨大的,所以你不能把它作为文字列表,考虑一个文件为之倾倒,然后用类似

If the list is huge, so you can't have it as a literal list, consider dumping it in a file and then using something like

for a in $(< my-numbers.txt)
do
  ./hw3_2_2 $a
done

的$(小于我-numbers.txt)部分是一种有效的方法(在击)来替代名称的内容的脚本该位置的文件。感谢丹尼斯·威廉姆森为指出,没有必要使用外部命令这一点。

这篇关于壳牌循环使用非整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆