Shell loops using non-integers?

后端 未结 6 1796
悲哀的现实
悲哀的现实 2021-02-01 22:05

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:



        
6条回答
  •  爱一瞬间的悲伤
    2021-02-01 22:54

    you can use awk to generate your decimals eg steps of0.1

    num=$(awk 'BEGIN{for(i=1;i<=10;i+=0.1)print i}')
    for n in $num
    do
      ./hw3_2_2 $n
    done
    

    or you can do it entirely in awk

    awk 'BEGIN{cmd="hw3_2_2";for(i=1;i<=10;i+=0.1){c=cmd" "i;system(cmd) } }'
    

提交回复
热议问题