Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

counts in "for ... do" loop

Status
Not open for further replies.

cruel

Programmer
Aug 6, 2001
131
I got an error message "./xx[10]: 1: not found" from testing the script below. It worked for me before in K-shell. Any tips? thanks

----------------------------------------------------
#! /bin/ksh

integer x=0
echo $x
for i in name1 name2
do
read $i?"Please enter a username: "
x= ` echo "$x + 1" | bc `
done
echo $x

 
i ALLWAYS write sh shells-scripts, NO c nor k
this is a portability request
csh is bad
ksh is not on all unix implemented.

#!/bin/sh
x=0
for i in name1 name2
do
echo "Please enter a username: "
read i
x=`echo "$x + 1" | bc`
done
echo $x


assignement in ALL shells does not allow spaces !!
q: what should this script do ??

vox clamantis in deserto.
 
korn shell is what I need to use. That is given. This script is an excerpt and has been simplified to explain the issue I am having. It intends to count how many users one has entered. Please ignore if the script piece makes sense or not. Last time I used the same thing but in Compaq UNIX, this time in HP, though both in korn shell. Thanks

by the way, xx if the script name.
 
Cruel:

Use whatever shell you want to use. Personally, I find the "purests" telling me what I should and shouldn't do, tiresome.

Regards,

Ed
 
Cruel, I tend to agree with olded about not worrying about the shell, particularly if porting the script isn't an issue, but jamisar is correct in that you should delete the space in your assignment, ie:

x= ` echo "$x + 1" | bc `

becomes

x=`echo "$x + 1" | bc`

HTH.
 
Thanks all for the reply. Space is the reason and I have three spaces too many!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top