Reputation: 15
I need to Loop user input for up to 10 times or until the user presses "n" and then echo out the list of words entered. When I run this I get the message: Directory stack not that deep
.
#!/bin/csh
echo "Enter Word"
set buffer = ("" "" "" "" "" "" "" "" "" "")
set count = 0
set argument = $<
while ($count <=10 && $argument != "n")
set buffer[$count] = $argument
@ count++
if ($argument = "n")
break
endif
set buffer [$count] = $argument
@ count++`enter code here`
end
echo $buffer
Upvotes: 1
Views: 1290
Reputation: 70947
That's my 1st csh script:
#!/bin/csh
set buffer = ('' '' '' '' '' '' '' '' '' '')
set count = 1
echo -n "Enter 1st Word: "
set argument = $<
while ($count <= 10 && $argument != "n")
set buffer[$count] = $argument
@ count++
if ($count <= 10) then
echo -n "Enter Word #"$count": "
set argument = $<
endif
end
set repl = 1
while ($repl < $count)
printf " %2d %s\n" $repl $buffer[$repl]
@ repl++
end
echo $buffer
echo "$buffer"
Play:
Enter 1st Word: Hello
Enter Word #2: good
Enter Word #3: world!
Enter Word #4:
Enter Word #5: End
Enter Word #6: now.
Enter Word #7: n
1 Hello
2 good
3 world!
4
5 End
6 now.
Hello good world! End now.
Hello good world! End now.
#!/bin/csh
set buffer = ('' '' '' '' '' '' '' '' '' '')
set count = 1
echo -n "Enter words: "
set argument = $<
set array = ($argument)
while ($count <= 10 && $array[1] != "n" && $#array > 0)
set buffer[$count] = $array[1]
@ count++
if ($count <= 10 && $#array > 1) then
shift array
else
break
endif
end
set repl = 1
while ($repl < $count)
printf " %2d %s\n" $repl $buffer[$repl]
@ repl++
end
echo $buffer
echo "$buffer"
Run:
Enter words: Hello good world. n Trick test
1 Hello
2 good
3 world.
Hello good world.
Hello good world.
Upvotes: 2