0

In a pattern rule I would like to export make variable like $(TargetLocation), $@.

I tried the following but It didn't get exported. The bash script is executable.

export $(TargetLocation); \
export $@; \
./EditHtml.sh;

I also tried this (I have used ${VarA} instead of ${TargetLocation} inside bash script), but it didn't get exported:

./EditHtml.sh VarA=$(TargetLocation); \

I would like to use these variables in the Bash script. Any suggestions?

1

You need to export the variable name, not the value.

You can either export the name for all sub processes with the GNU Make export statement

export TargetLocation

If you want the value just for one rule, then your statement must be regular shell syntax

    export TargetLocation="$(TargetLocation)"; \
    ./EditHtml.sh

In this case, depending on the content of the variable, quotes may be necessary, and it would still be vulnerable if there may be arbitrary values for the variable. On the other hand, if make runs with the privileges of the invoking user, there is no additional danger.

  • Thanks. This export TargetLocation didn't work but this export TargetLocation="$(TargetLocation)"; \ ./EditHtml.sh did work – Nikhil Sep 14 '18 at 18:01
  • 3
    Nicer looking: TargetLocation="$(TargetLocation)" ./EditHtml.sh (no need to export here). – Kusalananda Sep 14 '18 at 18:31
  • @Kusalananda While using your answer. Do we need to make EditHtml.sh executable? Also, is this a general shellscript syntax: I mean Can I pass variable to bashscript from terminal (outside make) as you did? Hoping that you could explain these things in an answer. – Nikhil Sep 16 '18 at 16:09
  • 2
    @Nikhil I won't write an answer for this. Using variable=value utility is standard shell syntax and will set variable to value in the environment of utility. If your script is not executable, you would need to use an explicit interpreter (bash or sh or whatever shell the script is written for) so that you have variable=value sh script. – Kusalananda Sep 16 '18 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.