Results 1 to 5 of 5
Hey I'm trying to make a script in tcsh but I'm getting some errors and I have some problems.
The script ask the user for a Internet provider and search ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 12-08-2005 #1Just Joined!
- Join Date
- Dec 2005
- Posts
- 1
Newbie (VERY) trying to make a tcsh script.
Hey I'm trying to make a script in tcsh but I'm getting some errors and I have some problems.
The script ask the user for a Internet provider and search in a file (car) full of emails to give some stats on how many people use that provider.
What's in the file car : First name, Name, email, date
The script :
echo "Enter the Internet Provider"
set providerName = "$<"
grep $providerName car >providerFile
Now after that, the problems start:
1. I want to assign the variable nb1 to the number of lines in the file providerFile.
I tried : set nb1 = $(wc -l providerFile) but it doesn't work.
I tried @ nb1 = $(wc -l providerFile) and it doesn't work and anyway, wc doesn't return a numerical value.
I think the error says Wrong file name or something.
Any ideas?
2. Even if I manage to make part 1 work, after that I need to create another variable called nb2 that contains the number of lines in the file car.
After that , I would need to be able to do mathematical operations with the 2 variables but the problem is that wc -l returns something like : 4 providerFile.
How do I make it so that it returns only a number? Or can I only cut it?
And if I can only cut it, I suppose I won't be able to do mathematical operations with the 2 variables (and assign the result to another variable)?
I could really use some help.
Thanks.
- 12-08-2005 #2Just Joined!
- Join Date
- Dec 2005
- Posts
- 9
your requirement seem a little complicate, maybe you can have a try on perl to solve the problem....
- 12-08-2005 #3Linux Engineer
- Join Date
- Jan 2005
- Location
- Chicago (USA)
- Posts
- 1,028
http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/
You'll also get a lot more support with Bash scripts.
- 12-09-2005 #4For arithmetic operations, do a 'man tcsh' and read up on '@' as a command....Code:
#!/bin/tcsh -f echo "Enter the Internet Provider" set providerName = "$<" set nb1 = `grep $providerName car | wc -l` set nb2 = `cat car | wc -l`
(It is true that some/certain things are "harder" to do in csh/tcsh than in bash or perl...
)
- 12-23-2005 #5Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
That's because csh and its derivatives are appalling for scripting. Bourne et al are the professionals' choice for good reason.
Originally Posted by a thing


Reply With Quote
