I want to print the whole array in tcsh, because then i want to pipe it to uniq, is there a way to do it in tcsh.

i had set array

and was printing it:

echo "$array"

but it ended up with error: Word too long, it works for smaller arrrays,

Is there some simple way to do it?

  • Also posted on Stack Overflow here. Nov 7, 2013 at 23:03
  • 1
    @Ricsie please show your whole script or steps you are performing. This could help to troubleshoot your problem. Nov 7, 2013 at 23:12

2 Answers 2


You must have a very old version of tcsh, that Word too long limit was removed in tcsh version 6.14.03 in 2006.

echo "$array"

Would pass the concatenation of the array elements to echo as one element but fail if any contain a newline character.

echo "$array:q"

would be more correct to pass the concatenation of all elements.

To pass all the elements of the array (except the empty ones; though that will be fixed in the next release) as separate arguments to echo, that would be:

echo $array:q

But if echo "$array" fails for you with Word too long, echo in that very old version may also fail with echo: Too many arguments..


In tcsh you'd use arrays as follow.

Define the array

set myarray = ( element1 element2 element3 element4 etc )

Output the whole array

printf '%s\n' "$array[-]"

Print element 1 to 3

printf '%s\n' "$array[1-3]"

NOTE: In Bash the first element of the array starts at 0 (zero).

Also add set verbose on top of your script to see what lines are interpreted and where it fails.

  • How would that address the Word too long error? Nov 7, 2013 at 23:04
  • @KeithThompson making sure he understands how arrays work in *csh shells. Nov 7, 2013 at 23:08
  • Ok, but echo "$array" should work perfectly well to print an entire array -- except for the "Word too long" problem, to which printf '%s\n' "$array[-]" is equally vulnerable. Nov 7, 2013 at 23:10
  • @KeithThompson except he shows set array only which will result to nothing (empty) output. He probably is overriding the array somehow and resulting in the error. set array; echo $array should return nothing, let alone "Word too long" Nov 7, 2013 at 23:16
  • 1
    Hmm. I assumed that set array was an abbreviation of the actual command he used. If he got "word too long", he's obviously setting it to something. Your recent comment on the question is a good one. Nov 7, 2013 at 23:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .