I expected the following loop to print numbers:
#!/bin/bash
# Basic range in for loop
for value in {1..5}
do
echo $value
done
but I get the following output in a single line: {1..5}
What am I doing wrong?
I expected the following loop to print numbers:
#!/bin/bash
# Basic range in for loop
for value in {1..5}
do
echo $value
done
but I get the following output in a single line: {1..5}
What am I doing wrong?
{1..5}
won't necessarily work like you expect it to in every circumstance. A better way to do this (to my mind, at least) is to use seq
:
for value in $(seq 1 5)
do
echo $value
done
seq
is a simple program included in basically every Unix that generates the sequence of numbers dictated by its two arguments.