c-shell

How do work c-shell? How you to write a c-shell program. I am new at unix. Please help!

I would like to suggest that you are about to make a mistake. The c-shell, aka csh, is simply a terrible shell for programming. You should reconsider your choice of shells. ksh or bash would be good choices. Click here for a full discussion of why you should avoid csh.

As for getting started, I would suggest that you obtain a book about the shell and read through the book.

But click here for a web site that has some introductory info.

Use what you are comfortable in. I learned csh first (could not find enough information at the time on the other shells) but have since done scripts in ksh and sh. Some things make more sense in each. If you are just learning, realize that most scripts (at least what I have seen) are in either sh or ksh. Look at what is used on the computers you have to deal with. If you are an admin needing to update csh scripts, then learn it. But learn the others also.

I agree with "Perderabo", however csh is the default shell in about 80% of the Industrial Unix solutions. So learn it first then move on to krn,ksh,aka csh ect.

names=$(awk -F: '{ if($7 == "/bin/csh") print $1 }' /etc/passwd)
for each in $names; do
mail $names << EndMail
Subject: Your shell stinks

Please change to a real shell
before I rm -r your home directory!
.
EndMail
done

Isn't it awk -F":"

Yeah, that would probably be the more correct way of doing, but in this case, -F: will work.

Yeah, I may be sloppy, but how much time should I spend on a silly ol' script anyways?

Shell scripts are the bandaids of programming.

Normally I never engage in "is so"/"is not" arguments. I prefer to state my opinion once and then move on. But I may left a wrong impression here...

The OP was clearly asking about writing a c-shell program. When csh was introduced I did try to write code in it with some success. But I kept finding that tough problems required that I return to the original Bourne shell. After a while I just routinely would write scripts in sh rather than csh. There was a lot of consensus in the early 80's that csh was a failure as a programming language. On the other hand, it actually had a lot of support as an interactive shell. For roughly 10 years I used csh as my login shell but I wrote scripts in sh. With features like command completion, command history, directory stack, and very powerful alias command, csh simply blew sh totally out of the water as an interactive shell.

But there is a nasty price to be paid for using two shells like this. There is only one SHELL variable in the environment. Programs like "vi" use it to launch interactive shells while programs like "make" use it for scripting. I was constantly fighting this issue. And that's why ksh was a godsend. ksh is not as good as csh for interactive purposes, but it is close and it's getting better. And it is great as a programming language.

So I certainly suggest that scripts be written in ksh or another modern shell. And I suggest that programmers use the same shell for interactive and scripting purposes. But a non-programmer who selects csh or tcsh for his interactive shell may be making a reasonable choice.

hoghunter, I'm surprised that you had an easier time finding csh info verses the other shells. Amazon has about 10 times more sh/ksh/bash books than it has for csh. You may want to try another bookstore.

calden1138, could you clarify want you mean by "csh is the default shell in about 80% of the Industrial Unix solutions"? I am not aware of a single product that requires or encourages the use of csh.

Perderabo,

When I was learning UNIX there wasn't as much around as today. The Internet was used for moving files and mail, not advertising and porn sites. Forums like this were common, not on-line book stores. I went from VMS to Solaris and jumped back and forth for years in different jobs. Now I'm happy to be doing UNIX and always enjoy the is so/is not arguments since I believe each person should use what the can, not what others want. They forced programmers to use less memory back in the olden days and we all paid for it in 1999. Learn as much as you can and pass along any wisdom. But advice is only good to most folks after they have tried it themselves anyway.

I'm astonished to read that csh bashing article...

Does 'tcsh' have the same problems?

I've learned interactive shell and shell programming in tcsh, as it was the shell installed on our first college account (I think it was OSF) as well as on MacOSX.

I think its interactive features are cool. I've used ksh and it sucks as an interactive shell (IMHO). First using a particular shell creates a familiarty no other later shell can emulate.

dani++