Newsgroups: comp.unix.questions,comp.unix.programmer > What's the correct way to set/use variables in make? > > Or, what's wrong with the following: > > test: > fls=`ls` > echo aaa $(fls) bbbb
Your "fls" is being set in a subshell, and then the next line invokes a different subshell, which has no knowledge of the first. To make that work, you either make fls a _make_ variable, for which all caps is a usual convention (but only a convention):
FLS= `ls`
test: echo aaa $(FLS) bbb
Or, if you don't need to access the variable any where else in the makefile, it's a little more efficient to simply continue the shell command on another line:
test: fls=`ls`; \ echo aaa $$(fls) bbb
Note that we need to escape the `$', to prevent "make" from trying to expand the variable before the shell sees it. With only one `$', it would likely come out `echo aaa bbb' (unless "fls" were also a make variable, which is less likely to happen if you stick to the convention of all caps for make variables.
Frederick
use $$fls instead of $$(fls) !
!! |
$ make -f make.pkg (set -vx; pwd=`pwd`; pwd=`basename $pwd`; cd ..; ls $pwd/* | grep -Ev 'make\.pkg|\.dxt|~' | archh bakfl $pwd -h) pwd ++ pwd + pwd=/home/tong/bin/pf/fileh-1.0 basename $pwd ++ basename /home/tong/bin/pf/fileh-1.0 + pwd=fileh-1.0 + cd .. + ls fileh-1.0/fdispatch.pm fileh-1.0/fileh.README fileh-1.0/fileh.diz fileh-1.0
$ make -f make.pkg (set -vx; pwd=`pwd`; pwd=`basename $(pwd)`; cd ..; ls $(pwd)/* | grep -Ev 'make\.pkg|\.dxt|~' | archh bakfl $(pwd) -h) pwd ++ pwd + pwd=/home/tong/bin/pf/fileh-1.0 basename $(pwd) pwd +++ pwd ++ basename /home/tong/bin/pf/fileh-1.0 + pwd=fileh-1.0 + cd .. pwd ++ pwd + ls /home/tong/bin/pf/FromText.pm /home/tong/bin/pf/HTML /home/tong/bin/pf/RCS /home/tong/bin/pf/argv_show.pl /home/tong/bin/pf/bibh.pl /home/tong/bin/pf/bt2td