Reputation: 1142
I have this non-functioning script, before I can attempt to fix it I need to know what kind of shell this was supposed to run in.
#
set pwrs = ( 0 0 0 0 0 0 0 0 )
@ pwrs[1]=1
@ next=2
while ( $next < 9 )
@ last = $next - 1
@ pwrs[$next] = $pwrs[$last] * 2
@ next = $next + 1
end
@count = 1
while ( $count <= 8 )
echo $pwrs[$count]
@ count = $count + 1
end
Upvotes: 1
Views: 52
Reputation: 37248
I was able to get this to produce appropriate output using csh
. I would expect tcsh
to work as well.
Turns out I do have a csh available. I pasted the code into the cmdline.
There was one error. All math calculations that begin with the @
char must be separated from their following variable name, hence
@count = 1
Needed to be fixed as
@ count = 1
$ set pwrs = ( 0 0 0 0 0 0 0 0 )
$ @ pwrs[1]=1
$ @ next=2
$ while ( $next < 9 )
while? @ last = $next - 1
while? @ pwrs[$next] = $pwrs[$last] * 2
while? @ next = $next + 1
while? end
$ @ count = 1
$ while ( $count <= 8 )
while? echo $pwrs[$count]
while? @ count = $count + 1
while? end
output
1
2
4
8
16
32
64
128
[oracle@localhost ~]$
See Grymoire Unix - Csh for explanation of the csh @
, and $pwrs[$next]
(array notation). Your specific case is not addressed, but you should be able to work it out. If you have other questions after you build small test cases that don't work, post them with sample inputs, expected outputs, and your current code and output.
Also, don't spend any more time on csh, while not as bad as some portray it, you will ultimately discover that there are problems you can't solve in csh. All of it's nice cmd-line features are included in bash, so you might want to consider using it.Finally, see Grymoire csh top 10 for detailed reasons why you want to convert this code to a newer shell.
IHTH
Upvotes: 2