getting rpoblem in assigning value to variable in if construct
Hi all,
i am trying to assignn value to varible in if construct. but it does not work. i have attched code snipshot for refernece. ADMIN_LANG = de-de es-es es-ES fr-fr fr-CA it-it ja-ja ko-ko LOCALE = ja-ja admin = ADMIN runtype = RUNTIME abc : check check: ( for x in $(ADMIN_LANG) ; do\ if [ $$x = "$(LOCALE)" ] ; then\ echo "enter in for loop" ;\ LANG_TYPE = $(admin);\ else \ LANG_TYPE = $(runtype);\ fi ;\ done ) ; echo $(LANG_TYPE); after that when i am trying to echo LANG_TYPE then it will show nothing. its very basic thing but i am facing problem. i have tried various combination to solve it but i am not succeded. please take a look into it. thanks, Ankit |
It looks like you have a typo:
Quote:
If you do have two $ symbols infront of the x try removing one. What are you writing this in? Suggest a slight re-write: Code:
ADMIN_LANG = "de-de es-es es-ES fr-fr fr-CA it-it ja-ja ko-ko" |
Sorry, my mind has been wandering a bit today!
Code:
#!/bin/bash |
both of suggeted code still does not work.i am writing makefile. try to run it on sygwin and linux both.
firstly it shows ...command commensed before first target..stop. then i declare one target as check.. after that it again flag error message as. for x in "de-de es-es..." syntax error : end of file unexpected please take a look into this issue. Thanks, Ankit |
I think you are confusing makefile macros with shell variables.
You can't set a shell variable inside a rule and have it persist after the rule, nor will it turn into a macro after the rule is done. |
i am not mixing shell variable in makefile.
but i can set value of macro(variable) in rule. in my first code snipshot , i tried to set value of LANG_TYPE depends upon the condition.after setting it i just check its value.but it still does not show anything. I declare macro(variable) LANG_TYPE with value runtime then i tried to set its value in if construct but it didnot change. it shows only previous value. i want to clear onething i am writing makefile not any script. |
Actually, you are writing a script inside the makefile,
the line that begins "for x in..." is a shell script. The make utility passes this text to the sh interpreter. Any variable you set inside this script is a real shell variable (not a makefile macro) and will not be visible after the sh script exits. You can not change makefile macros from within one of these embedded shell scripts, nor can you have a shell variable retain its value from one line in the rule to the next. In the rule you set a "shell variable" LANG_TYPE, it is not a macro. In the next line you're trying to echo the contents of LANG_TYPE. It does not work because they are in 2 different scripts because as stated above each line in the makefile rule is executed in a different subshell. So therefore the statement echo $(LANG_TYPE); has 2 problems, first it should be echo $$LANG_TYPE because LANG_TYPE is a shell variable not a macro. Second $$LANG_TYPE is still going to be "" empty string because its being executed in a different subshell from where you set it. |
Thanks a lot.
it clarify my doubt as well.. can u tell me any way to set varibale value depends upon condition. i give some idea about my problem. i have two target. i pass locale to makefile. depends upon the type of locale , i want to run perticular target. i have string of ADMIN_LANG = "de-de es-es es-ES fr-fr fr-CA it-it ja-ja ko-ko" i check whether locale is in ADMIN_LANG or not. so i need one if construct that check value of locale and set another macro or anyyhing that would be workable in this scenerio. plz suggest me any way. i stucked on this problem. Thanks and Regards, Ankit |
Two thinkgs come to mind,
first you can pass macro assigments to the make utility. Code:
$ cat makefile Code:
[0 randyd@entropy t]$ cat makefile |
actully makefile called from another file during compilation.we donot want to change at palce from where we call makefile.
now i am trying to call bash file in which i put logic. thanks for yr concern. anybody have ant suggestion .plz give me. |
All times are GMT -5. The time now is 01:02 PM. |