Get sequence of numbers in bash without using seq [duplicate]
This question already has an answer here:
How do I iterate over a range of numbers defined by variables in Bash?
18 answers
I want to loop over a sequence of numbers in a BASH script, but the bound values are not constants. I know this syntax:
for year in {2000..2010}; do
echo ${year}
done
But the values of 2000 and 2010 are changing in my case, so what I am doing right now is this:
for year in `seq ${yeari} ${yeare}`; do
echo ${year}
done
Is there a bash-native way to do the same, without using seq
?
bash seq
marked as duplicate by Inian
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 8:51
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How do I iterate over a range of numbers defined by variables in Bash?
18 answers
I want to loop over a sequence of numbers in a BASH script, but the bound values are not constants. I know this syntax:
for year in {2000..2010}; do
echo ${year}
done
But the values of 2000 and 2010 are changing in my case, so what I am doing right now is this:
for year in `seq ${yeari} ${yeare}`; do
echo ${year}
done
Is there a bash-native way to do the same, without using seq
?
bash seq
marked as duplicate by Inian
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 8:51
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How do I iterate over a range of numbers defined by variables in Bash?
18 answers
I want to loop over a sequence of numbers in a BASH script, but the bound values are not constants. I know this syntax:
for year in {2000..2010}; do
echo ${year}
done
But the values of 2000 and 2010 are changing in my case, so what I am doing right now is this:
for year in `seq ${yeari} ${yeare}`; do
echo ${year}
done
Is there a bash-native way to do the same, without using seq
?
bash seq
This question already has an answer here:
How do I iterate over a range of numbers defined by variables in Bash?
18 answers
I want to loop over a sequence of numbers in a BASH script, but the bound values are not constants. I know this syntax:
for year in {2000..2010}; do
echo ${year}
done
But the values of 2000 and 2010 are changing in my case, so what I am doing right now is this:
for year in `seq ${yeari} ${yeare}`; do
echo ${year}
done
Is there a bash-native way to do the same, without using seq
?
This question already has an answer here:
How do I iterate over a range of numbers defined by variables in Bash?
18 answers
bash seq
bash seq
edited Nov 23 '18 at 8:54
Micha Wiedenmann
10.5k1364106
10.5k1364106
asked Nov 23 '18 at 8:47
KostasKostas
232
232
marked as duplicate by Inian
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 8:51
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Inian
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 8:51
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Have a look at man bash
:
for (( expr1 ; expr2 ; expr3 )) ; do list ; done
First, the arithmetic expression expr1 is evaluated according to
the rules described below under ARITHMETIC EVALUATION. The
arithmetic expression expr2 is then evaluated repeatedly until
it evaluates to zero. Each time expr2 evaluates to a non-zero
value, list is executed and the arithmetic expression expr3 is
evaluated. If any expression is omitted, it behaves as if it
evaluates to 1. The return value is the exit status of the last
command in list that is executed, or false if any of the expres-
sions is invalid.
for ((i=yeari; i<yeare; i++))
do
echo $i
done
You might possibly also be interested in 'Arithmetic Expansion' ($((expression))
) of which you can find more in the man page.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Have a look at man bash
:
for (( expr1 ; expr2 ; expr3 )) ; do list ; done
First, the arithmetic expression expr1 is evaluated according to
the rules described below under ARITHMETIC EVALUATION. The
arithmetic expression expr2 is then evaluated repeatedly until
it evaluates to zero. Each time expr2 evaluates to a non-zero
value, list is executed and the arithmetic expression expr3 is
evaluated. If any expression is omitted, it behaves as if it
evaluates to 1. The return value is the exit status of the last
command in list that is executed, or false if any of the expres-
sions is invalid.
for ((i=yeari; i<yeare; i++))
do
echo $i
done
You might possibly also be interested in 'Arithmetic Expansion' ($((expression))
) of which you can find more in the man page.
add a comment |
Have a look at man bash
:
for (( expr1 ; expr2 ; expr3 )) ; do list ; done
First, the arithmetic expression expr1 is evaluated according to
the rules described below under ARITHMETIC EVALUATION. The
arithmetic expression expr2 is then evaluated repeatedly until
it evaluates to zero. Each time expr2 evaluates to a non-zero
value, list is executed and the arithmetic expression expr3 is
evaluated. If any expression is omitted, it behaves as if it
evaluates to 1. The return value is the exit status of the last
command in list that is executed, or false if any of the expres-
sions is invalid.
for ((i=yeari; i<yeare; i++))
do
echo $i
done
You might possibly also be interested in 'Arithmetic Expansion' ($((expression))
) of which you can find more in the man page.
add a comment |
Have a look at man bash
:
for (( expr1 ; expr2 ; expr3 )) ; do list ; done
First, the arithmetic expression expr1 is evaluated according to
the rules described below under ARITHMETIC EVALUATION. The
arithmetic expression expr2 is then evaluated repeatedly until
it evaluates to zero. Each time expr2 evaluates to a non-zero
value, list is executed and the arithmetic expression expr3 is
evaluated. If any expression is omitted, it behaves as if it
evaluates to 1. The return value is the exit status of the last
command in list that is executed, or false if any of the expres-
sions is invalid.
for ((i=yeari; i<yeare; i++))
do
echo $i
done
You might possibly also be interested in 'Arithmetic Expansion' ($((expression))
) of which you can find more in the man page.
Have a look at man bash
:
for (( expr1 ; expr2 ; expr3 )) ; do list ; done
First, the arithmetic expression expr1 is evaluated according to
the rules described below under ARITHMETIC EVALUATION. The
arithmetic expression expr2 is then evaluated repeatedly until
it evaluates to zero. Each time expr2 evaluates to a non-zero
value, list is executed and the arithmetic expression expr3 is
evaluated. If any expression is omitted, it behaves as if it
evaluates to 1. The return value is the exit status of the last
command in list that is executed, or false if any of the expres-
sions is invalid.
for ((i=yeari; i<yeare; i++))
do
echo $i
done
You might possibly also be interested in 'Arithmetic Expansion' ($((expression))
) of which you can find more in the man page.
answered Nov 23 '18 at 8:51
Micha WiedenmannMicha Wiedenmann
10.5k1364106
10.5k1364106
add a comment |
add a comment |