Message Board -  Archive

[ Login ] [ Create Account ]
[ Board List ] [ View Board ] [ Post Reply ]
  Author  Subject: Re: Rute, echo and scripts

Posted on 11-03-2003 02:00 a.m. ET  reply

Original Poster: Mark Krentel

> According to the book puting the command echo 'cat <filename>'
> with the cat filename in backquotes was supposed to just
> order the command cat to perform it's job.

No, echo is not some special command to make something else run.
Echo just prints whatever you give it, that's all.

Perhaps you're confusing Rute's examples. Skimming through the
chapter on "Shell Scripting", he uses a lot of examples like:

echo `expr 2 + 3`

Here, the backquotes run the expr command which produces 5, so echo
prints 5. But it's the backquotes, not echo, that invoke expr. It
would be simpler to use the following, which also prints 5.

expr 2 + 3

Actually, there's a sublty here. If you run:

echo `cat file`

Then the backquotes run cat (with argument "file") and the contents of
the file (the output of cat) are substituted for `...`. Assuming a
normal text file, this would be words separated by spaces and
newlines. So, echo gets many arguments: lots of words separated by
whitespace. And what echo does is print them separated by single
spaces. If instead, you run:

echo "`cat file`"

Then echo gets a single argument which is the contents of the file, so
in this case, it reproduces the file faithfully.

But the whole use of echo here is misleading. It would be simpler to
just run cat without the echo. Remember it's the backquotes, not
echo, that invoke cat. Echo is just a repeater.

And note: ' = single quote, ` = backquote.

P.S. Yes, I remember you. Sorry your job prevents you from coming to
most meetings. You seem to have a knack for asking questions that I
know something about.


< Previous 1 Next >

Site Contents