LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-04-2013, 11:47 AM   #1
amber1
LQ Newbie
 
Registered: Mar 2013
Posts: 8
Blog Entries: 1

Rep: Reputation: Disabled
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.
thanks
 
Old 03-04-2013, 12:29 PM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

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

Code:
for i in $(seq 1 29); do
    echo -n "$i "
done
echo ""
Regards,
 
1 members found this post helpful.
Old 03-04-2013, 12:35 PM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Seems homework... But try this one as well:
Code:
#!/bin/bash
i=1
while [ $i -le 30 ]; do
echo -n "$i "
i=$((i+1))
done
echo
 
Old 03-04-2013, 12:38 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Or just:
Code:
echo {1..29}
 
2 members found this post helpful.
Old 03-04-2013, 01:16 PM   #5
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

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

Why dont you try reading over http://www.tldp.org/LDP/Bash-Beginne...tml/index.html 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.
 
Old 03-04-2013, 01:50 PM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
When extended brace expansion (see post #4) is not available:
Code:
seq -s' ' 1 29
 
2 members found this post helpful.
Old 03-05-2013, 01:45 PM   #7
amber1
LQ Newbie
 
Registered: Mar 2013
Posts: 8

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Thank you for your help, I found them very helpful

Last edited by amber1; 03-05-2013 at 02:06 PM.
 
Old 03-05-2013, 02:02 PM   #8
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
removed since it no longer applies

Last edited by suicidaleggroll; 03-05-2013 at 07:24 PM.
 
Old 03-05-2013, 06:58 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Isn't that what he asked for
Quote:
output, with a white space between each number
??
 
Old 03-05-2013, 07:24 PM   #10
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by chrism01 View Post
Isn't that what he asked for

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

Last edited by suicidaleggroll; 03-05-2013 at 07:25 PM.
 
Old 03-05-2013, 10:32 PM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
I'll take your word for it ... in which case @amber1: don't edit posts, it just confuses people.
 
Old 03-06-2013, 03:45 AM   #12
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Quote:
Originally Posted by chrism01 View Post
@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
 
Old 03-06-2013, 04:19 PM   #13
amber1
LQ Newbie
 
Registered: Mar 2013
Posts: 8

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
okay sorry but thanks, you guys were alot of help.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Scripting Help thudpuppy Linux - Newbie 4 06-23-2012 03:00 PM
LXer: Scripting the Linux desktop, Part 2: Scripting Nautilus LXer Syndicated Linux News 0 02-17-2011 04:02 AM
Firefox Scripting Add-on (Scripting HTML / Javascript inside Firefox) linuxbeatswindows Programming 1 09-18-2009 10:09 PM
Help in scripting kkiwi8 Solaris / OpenSolaris 9 11-06-2007 07:37 PM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration