If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Help with command line arguments!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-29-03, 08:34
denizengt denizengt is offline
Registered User
 
Join Date: Oct 2003
Posts: 1
Red face Help with command line arguments!

Here's what I have so far. Yes, yes, I know. CSH. I MUST use it however.

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 (including multiple wildcards), 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?

Last edited by denizengt; 10-29-03 at 08:48.
Reply With Quote
  #2 (permalink)  
Old 10-29-03, 12:54
hacker hacker is offline
Registered User
 
Join Date: Oct 2003
Posts: 18
But you don't need to parse the command line and expand wildcards yourself. The shell does it for you. If users run your script with

./htx2 *.html > index.html

then your $argv will contain a list of all the html files, not the string "*.html". Was this what you were looking for? Maybe I misunderstood your question.

And why on earth do you need to use csh?

/Hacker
Reply With Quote
  #3 (permalink)  
Old 11-02-03, 19:27
sco08y sco08y is offline
Registered User
 
Join Date: Oct 2002
Location: Baghdad, Iraq
Posts: 697
Re: Help with command line arguments!

How does this work for ya:

set title = "File Index"

#defines head
cat - <<HEADER
<html>
<head>
<title>
$title
</title>
</head>
<body>
<h1>
$title
</h1>
<hr>
<table>
HEADER

#begin loop
foreach a($*)

The rest is straightforward.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On