Ubuntu Forums Archive Viewer

[SOLVED] very stupid, simple bash script problem - for loop

Archived thread 1003746 from Programming Talk. Markdown source: Programming_Talk/thread_1003746_[SOLVED]_very_stupid,_simple_bash_script_problem_-.md

Original URL About this archive
#1

Just a little question. I've been writing bash scripts for quite a while and, whilst I always get there in the end, I usually find little things that don't work when I think they should. I usually just use another method, but his one puzzles me....

Simple example (that doesn't work):

MAX=20
for count in {1..$MAX}; do
     ...
done

why can't I put a variable in the braces?

Thanks for reading

-s

#2

[PHP]#!/bin/bash MAX=20 for count in $(seq 1 "$MAX"); do echo "$count" done [/PHP]

#3

unutbu said: [PHP]#!/bin/bash

MAX=20 for count in $(seq 1 "$MAX"); do echo "$count" done [/PHP]

ah, thanks for that!

#4

Or:


MAX=20

for (( i = 0; i < $MAX; ++i ))
do
        echo -n "$i "
done
echo ""
#5

dwhitney67 said: Or:


MAX=20

for (( i = 0; i < $MAX; ++i ))
do
        echo -n "$i "
done
echo ""

lol - I spent 5+ years using c (and similar) yet I've never used that method in a bash script. Thanks