I very new to C Shell. I am trying to read a file from the command line, and determine whether it's a zip file, a .txt, a symbloic link, a pipe, or whatever ("unknown").

Then I'd like to execute a few instructions depending on the type. For instance, if it's a txt file, print information about it ("it's a text file") and give its size.

Here is what I what got so far:

#!/bin/csh

if ($#argv < 1) then
   echo "Usage: $0 file [...]"
   exit 1
endif

foreach file ($*)
    set ft=`file $file | cut -d: -f 2`
    switch ("$ft")
       case "*Zip*":
           echo "$file is a zip file"
           breaksw
       case "*shell script*":
           echo "$file is a shell script"
           breaksw
       case "*ASCII*":
           echo "$file is ascii"
           breaksw
       case "*symbol*":
           echo "$file is a link"
           breaksw
   endsw
end

Firstly, you have palced your question in the wrong forum. c shell (csh) is a command line interpreter of unixoid systems unlike c which is a programming language, although there is a slight resemblance in the syntax.
As for your question, it largely depends which commanda you would like to perfrom on those files. You have only said what you'd like to do with text files. For the text file you could invoke the ls command and pipe it as input to awk or even grep with which you could extract the size using regular expresion.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.