LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-26-2004, 03:07 AM   #1
wcfour
LQ Newbie
 
Registered: Nov 2004
Posts: 2

Rep: Reputation: 0
Shell Script


Hi I am new to this forum, any help would be appreciated.

I am trying to figure out how to write a script to display the numbers 1 - 9 in a row (one at a time.) Using a while loop.
For example:
1
12
123
1234
etc...

thx
 
Old 11-26-2004, 03:22 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Looks like an assignement ...
Who ever want to do that in the real life ?
 
Old 11-26-2004, 03:28 AM   #3
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
Code:
line=
for number in 1 2 3 4 5 6 7 8 9; do
  line="${line}${number}"
  echo "$line"
done
or
Code:
line=
number=1
while [ $number -lt 10 ]; do
  line="${line}${number}"
  number=$(( $number + 1 ))
  echo "$line"
done
 
Old 11-26-2004, 03:37 AM   #4
wcfour
LQ Newbie
 
Registered: Nov 2004
Posts: 2

Original Poster
Rep: Reputation: 0
script

theYinYeti

Thank you
 
Old 11-26-2004, 05:24 AM   #5
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
That one is cooler
Code:
echo "1
12
123
1234
12345
123456
1234567
12345678
123456789" | while read s
do
echo $s
done
 
Old 11-26-2004, 05:31 AM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Can i Please remind LQ members that there is no benefit to another member's learning if you give them a straight solution to their course work. give hints, not soutions. thanks.
 
Old 11-26-2004, 06:05 AM   #7
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Can i Please remind LQ members that there is no benefit to another member's learning if you give them a straight solution to their course work.
That was precisely my goal in my first reply, but theYinYeti missed it.
I provided a dumb answer later just for fun, I doubt wcfour will get an A+ with it ...
 
Old 11-26-2004, 06:07 AM   #8
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
Is that so? ... I was indeed surprised by the request... But then, I've done myself so strange things to achieve usefull results in shell scripting...
 
  


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
Shell script inside shell script treotan Linux - General 4 02-19-2009 06:34 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM
[SHELL SCRIPT] Write at the right of the shell window Creak Linux - General 2 04-02-2004 03:00 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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