Using seq (Or alternative)

I usually just browse the forum/google for answers, however I've been stuck on a problem for a number of hours now and I've decided to join up and actually ask I've searched the forum ad naseum in an attempt to find answer to my query, however so far I have been unsuccessful.

I'm no expert infact I've been writing shell scripts for all of 2 days.

Basically I want to read in 3 values, set that to a sequence, output to a file then read the values of various lines in as I want to later on.

read first 
read increment 
read last 

seq $first $increment $last > output.dat

However, my problem is as such.

When I read in a value of -20.0 it gets set to -20 This is not acceptable for me.

How can I get the format of x.0 bearing in mind sometimes the first value will be x.y

Thanks.

Hi, gtc, and welcome to the forums.

You can use printf to ensure that numbers have a specified precision:

printf '%.1f\n' -20
-20.0

For your situation, if you require all numbers to be similarly formated, perhaps:

seq $(printf '%.1f ' $first $increment $last) > output.dat

Regards,
Alister

Spot on.

It would have made more sense to just join up a few hours ago and ask rather than assure myself I could figure it out. Oh well, what doesn't kill us...

Many thanks for the reply.

Depending on your shell, it may not support floating point numbers, and only treat them as strings.