The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
a simple loop in csh dsstamps UNIX for Dummies Questions & Answers 1 05-22-2008 03:03 AM
simple while loop ali560045 Shell Programming and Scripting 10 12-26-2007 10:44 AM
simple for loop ali560045 Shell Programming and Scripting 3 12-17-2007 01:39 AM
Simple loop query kutz13 UNIX for Dummies Questions & Answers 2 07-17-2007 03:13 PM
Simple while loop question Brokeback Shell Programming and Scripting 3 07-21-2006 09:04 AM

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-07-2006
syno syno is offline
Registered User
  
 

Join Date: Mar 2006
Location: North West UK
Posts: 3
a simple while loop

Hallo everyone

I might just be being dumb, but I am using the BASH shell and cannot get the following script to work:

x=0
while [ $x -lt 10 ]
do
echo $x
x=´echo "$x + 1" | bc´
done

Can anybody help me out. I am just get a repeating output saying:
bc: command not found
0 + 1: command not found

Any suggestions would be helpful

Last edited by syno; 04-07-2006 at 07:21 PM.. Reason: Incorrect spelling
  #2 (permalink)  
Old 04-07-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,719
Code:
x=`echo "$x + 1" | bc`
... backticks ....
  #3 (permalink)  
Old 04-07-2006
mph mph is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 58
You could also use
Code:
x=$((x+1))
  #4 (permalink)  
Old 04-07-2006
sssow sssow is offline
Registered User
  
 

Join Date: Aug 2001
Posts: 179
Also can use let

x=0
while [ $x -lt 10 ]
do
echo $x
let x=x+1
done
  #5 (permalink)  
Old 04-07-2006
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
bash also has the for loop constuct
Code:
for (( x=0 ; x<10 ; x++ )) 
do 
    echo $x
done
  #6 (permalink)  
Old 04-08-2006
syno syno is offline
Registered User
  
 

Join Date: Mar 2006
Location: North West UK
Posts: 3
Thanks guys!

You have been a real help
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 03:55 PM.


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