Thread: C-Shell Scripting.. Help!

  1. #1
    Registered User denizengt's Avatar
    Join Date
    Sep 2003
    Posts
    19

    C-Shell Scripting.. Help!

    Ok, recenty I've been trying to automate tasks. It was recommended that I learn CSH. So off I go, and learn some simple CSH, but I don't get how to do the following task.

    I'm trying to create a script, that creates a HTML file, say INDEX.HTML, for files listed on the command line. No linking or anything, just puts the names of the files on the command line inside the INDEX.HTML file.

    I have no idea how to go about this, any pointers or examples?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    csh is the most damaged of the shells available to you
    Counterpoint

    Also, CSH != C

    In normal Bourne shell / bash / ksh, it would be this
    Code:
    #!/bin/sh
    
    cat << HERE
    this is the head of the html file
    HERE
    
    for i; do
      echo $i
    done
    
    cat << HERE
    this is the tail of the html file
    HERE
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User denizengt's Avatar
    Join Date
    Sep 2003
    Posts
    19
    Here's what I have so far

    Code:
    #!/bin/csh -f
    
    set params = $argv[1-] 
    set argc = $#argv
    set lsval = `ls`
    set title = "File Index"
    
    #defines head
    echo "<html>"
    echo "<head>"
    echo "<title>"
    echo "$title"
    echo "</title>"
    echo "</head>"
    echo "<body>"
    echo "<h1>"
    echo "$title"
    echo "</h1>"
    echo "<hr>"
    echo "<table>"
    
    #begin loop
    set var = `ls`
    foreach a($var)
    	
    
    	echo "<tr>"
    	echo "<td>"
    	echo "<pre>"
    
    	echo " $a "
    
    	echo "</pre>"
    
    	echo "</td>"
    
    	echo "</tr>"
    
    end
    #loop end
    
    #defines bodyend
    echo "</table>"
    echo "<hr>"
    echo "<address>"
    echo "Generated by $USER@`hostname` from $HOME"
    echo "</address>"
    The problem I have now, is that I don't know how to 'scan' the argument list stored in argv. Ideally, I want the program to be run

    uprompt> ./htx2 *.html > index.html

    So this means whatever the extension is , say *.c *.h, the script will find it in argv, and place it in var, so var = `ls *.html` say. Then only files with the html extension will be listed in the html file.

    How can I do this. I've tried and cannot seem to get it. The users input, *.html, or *.c or whatever, can occur anywhere in the argv line. So it could follow other switches, whatever. How can I scan the line, and pass the search term to ls?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > foreach a($var)
    For the command line params, type
    foreach a ($*)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c shell scripting!!
    By docetes in forum Linux Programming
    Replies: 2
    Last Post: 03-17-2006, 06:02 AM
  2. Shell Scripting...redirecting executable output?
    By Kleid-0 in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 05-13-2005, 10:50 AM
  3. Directories + shell scripting
    By MethodMan in forum Linux Programming
    Replies: 2
    Last Post: 03-28-2002, 12:07 AM
  4. shell scripting ????
    By Unregistered in forum C Programming
    Replies: 0
    Last Post: 02-14-2002, 04:31 PM