-   Linux - Newbie (
-   -   Need Help Scripting? (

amber1 03-04-2013 11:47 AM

Need Help Scripting?
I am new to scripting and just needed some help writing a script please. How can I write a script which prints the numbers 1-29 on one line of the standard output, with a white space between each number?

I would appreciate it if someone can please help.

Snark1994 03-04-2013 12:29 PM

What language do you want to use? In bash, it would be something like


for i in $(seq 1 29); do
    echo -n "$i "
echo ""


shivaa 03-04-2013 12:35 PM

Seems homework... But try this one as well:

while [ $i -le 30 ]; do
echo -n "$i "

suicidaleggroll 03-04-2013 12:38 PM

Or just:

echo {1..29}

Kustom42 03-04-2013 01:16 PM

Yea after reading the first two was wondering why they were doing loops. Maybe as training?

Why dont you try reading over so you can get a full understanding of what is actually happening here. The brackets in the echo will do something called "bash expansion" try looking up that term if you are curious.

colucix 03-04-2013 01:50 PM

When extended brace expansion (see post #4) is not available:

seq -s' ' 1 29

amber1 03-05-2013 01:45 PM

Thank you for your help, I found them very helpful

suicidaleggroll 03-05-2013 02:02 PM

removed since it no longer applies

chrism01 03-05-2013 06:58 PM

Isn't that what he asked for

output, with a white space between each number

suicidaleggroll 03-05-2013 07:24 PM


Originally Posted by chrism01 (Post 4905516)
Isn't that what he asked for


Post #7 was edited after I responded, so my response now makes no used to make sense, I promise!

chrism01 03-05-2013 10:32 PM

I'll take your word for it ;) ... in which case @amber1: don't edit posts, it just confuses people.

Snark1994 03-06-2013 03:45 AM


Originally Posted by chrism01 (Post 4905630)
@amber1: don't edit posts, it just confuses people.

Or more precisely, don't edit your post to substantially change its content. It's normally considered better to edit your post to append content than to double-post, and of course editing your post to correct typos is fine ;)

amber1 03-06-2013 04:19 PM

okay sorry but thanks, you guys were alot of help.

All times are GMT -5. The time now is 08:44 PM.