Unix Shell - csh: what is wrong with this loop command

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > February 2005 > csh: what is wrong with this loop command





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author csh: what is wrong with this loop command
clinton__bill@hotmail.com

2005-02-22, 5:53 pm

Hi,
I am learning using C-shell and I have this simple script,


#!/bin/csh

foreach f ("http://someweb1.html "\
"http://someweb2.htm "\
"http://someweb3.htm")

wget -t ifn $f

end


But I get this error,

: Command not found.
Too many ('s.

Do you see what is wrong?

Ed Morton

2005-02-22, 5:53 pm



clinton__bill@hotmail.com wrote:
> Hi,
> I am learning using C-shell and I have this simple script,
>
>
> #!/bin/csh
>
> foreach f ("http://someweb1.html "\
> "http://someweb2.htm "\
> "http://someweb3.htm")
>
> wget -t ifn $f
>
> end
>
>
> But I get this error,
>
> : Command not found.
> Too many ('s.
>
> Do you see what is wrong?
>


No, but take a look at question 19 in the FAQ:
http://home.comcast.net/~j.p.h/cus-faq.html#S

Ed.
Bruce Barnett

2005-02-22, 8:49 pm

clinton__bill@hotmail.com writes:

> #!/bin/csh
>
> foreach f ("http://someweb1.html "\
> "http://someweb2.htm "\
> "http://someweb3.htm")
>
> wget -t ifn $f


It works with my csh on Linux.

But as it's the C shell, and it's noted for being unpredictable.

Perhaps you need spaces before and after the ")" characters?
I'd also add the -f flag:

-----------
#!/bin/csh -f

foreach f ( "http://someweb1.html "\
"http://someweb2.htm "\
"http://someweb3.htm" )

wget -t ifn $f
end
----
csh doesn't like long lines. And if the number of files grow, you will
have problems.

--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.
Keith Thompson

2005-02-23, 2:51 am

clinton__bill@hotmail.com writes:
> Hi,
> I am learning using C-shell and I have this simple script,
>
>
> #!/bin/csh
>
> foreach f ("http://someweb1.html "\
> "http://someweb2.htm "\
> "http://someweb3.htm")
>
> wget -t ifn $f
>
> end
>
>
> But I get this error,
>
> : Command not found.
> Too many ('s.
>
> Do you see what is wrong?


No, you shouldn't be getting those errors from the script you posted.
Is that really the exact script you tried to run, or did you re-type
it? Always cut-and-paste any code samples so we can address your
actual problems without getting bogged down in random typos.

Presumably you meant "-t inf" rather than "-t ifn".

A csh script should almost always have a "-f" option on the "#!" line
so it doesn't source the user's ~/.cshrc file.

The quotation marks are superfluous. They're necessary if the URLs
happen to contain shell metacharacters, but then you probably don't
want the extra blanks. Single quotes are probably better than double
quotes if you don't want any variable references to be expanded.

Your script, as posted, *should* work assuming the URLs are valid and
assuming you fix the "-t ifn" typo.

*If* I were doing to do this as a csh script, I'd probably write it
like this:

#!/bin/csh -f

foreach f ( 'http://someweb1.html' \
'http://someweb2.htm' \
'http://someweb3.htm' )
wget -t inf $f
end

Or, for something this simple, I might use a one-line command rather
than a shell script:

< list-file xargs -n 1 wget -t inf

where "list-file" is file containing a list of URLs.

Yes you can put the "< list-file" redirection at the beginning of the
line; in this case, it makes the data flow clearer. (This is true for
both csh/tcsh and sh/ksh/zsh/bash.) If you prefer, you can also write
it as:

xargs -n 1 wget -t inf < list-file

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Christopher W Aiken

2005-02-23, 8:47 pm

On 22 Feb 2005 14:35:33 -0800, clinton__bill@hotmail.com wrote:

>Hi,
> I am learning using C-shell and I have this simple script,
>
>
>#!/bin/csh
>
>foreach f ("http://someweb1.html "\
>"http://someweb2.htm "\
>"http://someweb3.htm")
>
>wget -t ifn $f
>
>end
>
>
> But I get this error,
>
>: Command not found.
>Too many ('s.
>
>Do you see what is wrong?



Looks like you start a string with a single quote and end the string
with a double qoute. Change all to either single or to double and
don't mix.

-=[cwa]=-

--
-=[cwa]=-
email: chris at cwaiken dot net
home: www.cwaiken.net
Keith Thompson

2005-02-24, 5:58 pm

Christopher W Aiken <chris@nospam.net> writes:
> On 22 Feb 2005 14:35:33 -0800, clinton__bill@hotmail.com wrote:
>
>
>
> Looks like you start a string with a single quote and end the string
> with a double qoute. Change all to either single or to double and
> don't mix.


No, there are no single quote characters in the OP's code, and the
message

Too many ('s.

indicates mismatched parentheses, not by a single quote problem.

As I mentioned elsethread, I don't believe the posted code would
produce the specified error message. There must be something else
going on.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com