Re: 2 simple shell related questions



Thanks, I should have tried harder to look for the answers :) .

On Oct 10, 6:02 pm, "Chris F.A. Johnson" <cfajohn...@xxxxxxxxx> wrote:
On 2007-10-11, babaji wrote:

Newbie alert!

Hello everyone :) . I have two simple questions regarding shell
variables. I tried looking for the answers on the net but couldn't
find an exact match.

Q1: what does $^ represent
Q2: what does $@ represent

I saw both in a makefile and searched the GNU make document which has
references to these symbols but does not explain clearly what they
stand for (or maybe I didn't get it!) . I searched on google too but
came up with not so clear results.

From what I know $ is used to get the value of a shell var, and so ^
or @ must stand for something like a special-var.

I know what $#, $0/1/2... and $* are used for but can't get an idea
about these two :)

They are not shell variables; a makefile is not a shell script. See
the documentation for make:

Automatic Variables

`$@'
The file name of the target of the rule. If the target is an
archive member, then `$@' is the name of the archive file. In a
pattern rule that has multiple targets (*note Introduction to
Pattern Rules: Pattern Intro.), `$@' is the name of whichever
target caused the rule's commands to be run.

`$^'
The names of all the prerequisites, with spaces between them. For
prerequisites which are archive members, only the member named is
used (*note Archives::). A target has only one prerequisite on
each other file it depends on, no matter how many times each file
is listed as a prerequisite. So if you list a prerequisite more
than once for a target, the value of `$^' contains just one copy
of the name.

--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence


.



Relevant Pages

  • Re: 2 simple shell related questions
    ... They are not shell variables; a makefile is not a shell script. ... The file name of the target of the rule. ... pattern rule that has multiple targets (*note Introduction to ... A target has only one prerequisite on ...
    (comp.os.linux.misc)
  • Automatic variable $^ in makefile
    ... Here is quote from ... prerequisites which are archive members, only the member named is used ... A target has only ... times each file is listed as a prerequisite. ...
    (comp.unix.programmer)
  • Re: Different COMPFLAGS for different OBJS in Makefile
    ... TARGET = target.exe ... doit: $ ... built-in pattern rule, for that matter): ...
    (comp.unix.programmer)