getting rpoblem in assigning value to variable in if construct
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
( 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.
#!/bin/bash
ADMIN_LANG="de-de es-es es-ES fr-fr fr-CA it-it ja-ja ko-ko"
LOCALE=${LOCALE:-ja-ja}
check_type=0
for x in ${ADMIN_LANG}
do
if [ "$x" = "${LOCALE}" ]
then
check_type=`expr ${check_type} + 1`
fi
done
echo "Language Type: \c"
if [ ${check_type} -eq 0 ]
then
export LANG_TYPE="RUNTIME"
else
export LANG_TYPE="ADMIN"
fi
echo "${LANG_TYPE}"
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
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.