[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: Newbie - shell program problem



Hello,

A more exhaustive explanation of the problem... (experts can look away:)

The following line does not produce intended output because of the space
around the = sign (a previous poster had already mentioned this).

On Sun, 29 Oct 2000, YL Narayana wrote:
> MATCHES = `ls -d $1 2>/dev/null | wc -l`

Well, what exactly is happening here?? Consider the following shell code...

VAR=foo prog

This sets the environment variable VAR to the value "foo" and runs the program
prog. Where can this be usefull??

http_proxy="10.0.0.1:8000" wget http://www.python.org

Now, I have set the environ variable "http_proxy" to point to my proxy and
I've run wget to download the given URL through the proxy. A usefull trick.

In your case, you set the environment variable MATCHES to an empty string and
tried to run the output of `ls -d ...<snip>...` as a program. Not what you
expected.

While debugging shell scripts, use set -x and set -v.

It seems that shell programmers know little about coding style...
What you are probably thinking now is correct, "the shell is stupid!". True,
the shell merely does string manipulation and is quirky and you will have to
live with it. Unfortunately so.

For more complex shell scripts, I tend to use python instead. Python is a very
clean language with a simple syntax that programmers proficient in other
languages can learn very quickly. Give it a try (www.python.org), I'm sure
you'll love it.

- Raja Supe