Linux - Loop User input in CSH -


i need loop user input 10 times or until user presses "n" , echo out list of words entered. when run message: directory stack not 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 

1st try

that's 1st 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)     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: enter word #3: world! enter word #4:  enter word #5: end enter word #6: now. enter word #7: n   1  hello   2    3  world!   4     5  end   6  now. hello world! end now. hello world!  end now. 

or iterate on arguments on same input

#!/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)     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 world. n trick test   1  hello   2    3  world. hello world. hello world. 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -