Find the answer to your Linux question:
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.
  1. #1
    Just 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.

  2. #2
    Just 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....

  3. #3
    Linux 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.

  4. $spacer_open
    $spacer_close
  5. #4
    Banned CodeRoot's Avatar
    Join Date
    Sep 2005
    Posts
    567
    Code:
    #!/bin/tcsh -f
    echo "Enter the Internet Provider"
    set providerName = "$<"
    set nb1 = `grep $providerName car | wc -l`
    set nb2 = `cat car | wc -l`
    For arithmetic operations, do a 'man tcsh' and read up on '@' as a command....

    (It is true that some/certain things are "harder" to do in csh/tcsh than in bash or perl... )

  6. #5
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Quote Originally Posted by a thing
    http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/

    You'll also get a lot more support with Bash scripts.
    That's because csh and its derivatives are appalling for scripting. Bourne et al are the professionals' choice for good reason.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •