[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bultin shell variable in Makefile
From: |
Paul Smith |
Subject: |
Re: Bultin shell variable in Makefile |
Date: |
Mon, 06 Jul 2009 09:16:25 -0400 |
On Mon, 2009-07-06 at 05:01 -0700, rama krishna wrote:
>
> Hi All,
>
> When I am trying to use a predefined shell variable RANDOM in a make
> file.
> I am not able to generate any random value.
> Instead it is showoing as blank.
>
> The code I am using is :
>
> SEED := $(shell /bin/sh -c "$(RANDOM)")
>
> I am not getting any error but, the value is blank.
> Can anybody help me in solving the problem.
$RANDOM is a special variable in the shell. But you are using a make
variable $(RANDOM) here, which is not set to anything. So make expands
this command to "/bin/sh -c """, which does nothing obviously. So the
result is nothing.
Also, $RANDOM is a special feature of bash; it's not part of a standard
POSIX shell. So you should be explicitly requesting that the command be
run by bash, not /bin/sh, or it will not be portable. At least if you
run bash explicitly then systems which don't have bash will see some
kind of error message rather than getting an empty string.
I think you want:
SEED := $(shell /bin/bash -c "echo $$RANDOM")
(note, not tested!)
--
-------------------------------------------------------------------------------
Paul D. Smith <address@hidden> Find some GNU make tips at:
http://www.gnu.org http://make.mad-scientist.us
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist