keepcalculator

06 Numbers and Powers

Bash Associative Array: Syntax & Examples

Card No. 06·55279 · Updated · Standard formula, shown below

Average pace 5.00 min/km
Average speed
12.00 km/h
Result
Finish time
50 min
You entered
Distance
10 km
You entered
You enter
Finish time, Distance
You get
Average pace, Average speed
Rounding
2 dp

Bash associative arrays let you store key-value pairs in a shell script, so you can look up a value by a name instead of a numeric index. You declare one with declare -A, then assign and read entries using ["key"] syntax. This article explains how they work, how to use them in real scripts, and the common pitfalls that trip up even experienced shell users.

Formula

Pace = Finish time ÷ Distance
Speed = Distance ÷ (Finish time ÷ 60)

Where:
– Finish time (t) is in minutes
– Distance (d) is in kilometers
– Pace is in minutes per kilometer
– Speed is in kilometers per hour

Worked Example

Using the default values: t = 50 minutes, d = 10 km.

Step 1: Pace = 50 ÷ 10 = 5.00 min/km
Step 2: Speed = 10 ÷ (50 ÷ 60) = 10 ÷ 0.8333 = 12.00 km/h

The calculator block above gives the same results: 5.00 min/km and 12.00 km/h.

When to Use This Calculator

Use this tool to plan a run, walk, or cycle route. Enter a target finish time and a known distance to get the average pace you need to hold. It is also useful for converting a pace you already ran into a speed, which is how many treadmill displays show intensity.

The result is a single average number. It does not account for hills, wind, stops, or uneven effort. If your route has elevation gain or you plan to walk through aid stations, expect your actual pace to vary.

How to Read the Result

The pace output is the time it takes to cover one kilometer. A lower number means faster. For example, 4.50 min/km is faster than 6.00 min/km. The speed output is simply the inverse: how many kilometers you cover in one hour at that pace.

If you are used to miles, convert the distance to kilometers first (1 mile = 1.60934 km). Then the pace will be in minutes per kilometer, not minutes per mile.

Common Mistakes

  • Mixing units: entering distance in miles but expecting a min/km pace gives a wrong number. Convert first.
  • Using seconds in the time field: the calculator expects minutes. 90 minutes, not 1:30.
  • Rounding too early: if you round pace to 5.0 and then compute speed from that, you get 12.0 instead of 12.05. The calculator rounds only at the end.
  • Forgetting that pace and speed are reciprocals: a 10% faster speed is not a 10% lower pace. The relationship is inverse.

Limits of the Formula

This is a simple average formula. It assumes you move at a constant speed for the entire distance. Real runs have acceleration, deceleration, and stops. It also ignores the fact that running economy changes with speed: holding 4:00 min/km for 5 km is very different from holding it for 42 km.

The formula is exact for the arithmetic, but the real-world application is an estimate. Use it for planning, not for predicting race day performance.

Frequently Asked Questions

Can I use this for walking or cycling? Yes. The math works for any activity where you cover a distance over time. Walking pace will be slower (higher minutes per km), cycling faster (lower minutes per km).

What if I run on a treadmill at a set speed? Enter the speed you want, then use the reverse calculation: distance = speed × time. This calculator gives speed from time and distance, so you can also enter a distance and a target time to see what speed to set.

How do I convert min/km to min/mile? Multiply the pace in min/km by 1.60934. For example, 5.00 min/km × 1.60934 = 8.05 min/mile.

Is a lower pace always better? For a fixed distance, yes. Lower pace means less time. But for training, you do not always want the fastest pace; easy runs are intentionally slower.

What is a good pace for a beginner? There is no universal answer. A common starting point for a 5 km run is 7–8 min/km, but it depends on age, fitness, and experience. Start comfortably and gradually speed up.

Related

Formula used
in t | Finish time | min | 50 | 0
in d | Distance | km | 10 | 0 | 100000
out pace | Average pace | min/km | t / d | 2
out speed | Average speed | km/h | d / (t / 60) | 2

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →