The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-28-2008
kim187 kim187 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 8
Cool help with scrpit

my friend has quized me.. I'm very new to scripts but I know I'm somewhat close

any help would be a major help..
here is the script

ex

shell program, hello, to display the phrase "hello world" 50 times (script should verify the

count) . Do not use a for loop! (hint should show hello world 1 ..... hello world 50 )

i put this

#!/bin/bash

count=1
max=50

while [ $count -le $max ] // a test of a condition -le another value
do
echo "Hello world $count"
let count=count+1

I still get a error.

any help would be nice thanks

airmax_sk@yahoo.com
  #2 (permalink)  
Old 04-28-2008
Cameron's Avatar
Cameron Cameron is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2001
Location: Brisbane, Australia
Posts: 500
You were on the right track.
However your comment syntax was wrong & you needed to end the while loop with "done"...
Code:
#!/bin/bash

count=1
max=50

while [ $count -le $max ] ## a test of a condition -le another value
do
echo "Hello world $count"
let count=count+1
done
Cheers,
Cameron
  #3 (permalink)  
Old 04-28-2008
kim187 kim187 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 8
thanks

yah it gets a bunch of hellos out there


I must have forgot about the done command. no systex error.

i thought I put that on the command thanks for help cameron
  #4 (permalink)  
Old 04-29-2008
chella chella is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 75
Hi,

Without using any loops you can get the same output. Just give a try on it.

Code:
yes "hello world" | head -50| grep -n "hello world" | awk -F: '{print $2" "$1}'
Regards,
Chella
  #5 (permalink)  
Old 04-29-2008
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
  
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 393
An awk trick:
Code:
awk 'BEGIN{$50=OFS="\nHello world";print}'|awk '!/^$/ {print $0,NR-1}'
  #6 (permalink)  
Old 04-29-2008
Cameron's Avatar
Cameron Cameron is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2001
Location: Brisbane, Australia
Posts: 500
Neat trick Klashxx.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0