Problem isolating the environment variable in a shell script

1

I’m a novice here but stackoverflow has helped me in the past.

I’m writing a bash shell script to generate a makefile (starting small).

echo "\
include \$(GNUSTEP_MAKEFILES)/common.make

APP_NAME = $PRODUCT_NAME
$PRODUCT_NAME_OBJC_FILES = source.m

include \$(GNUSTEP_MAKEFILES)/application.make"\
> GNUmakefile

The environment variable set by the IDE where this is used is $PRODUCT_NAME. Now, bash obviously treats this script as referencing an environment variable $PRODUCT_NAME_OBJC_FILES. I see why, but I don’t know how to get around it. Any pointers?

$PRODUCT_NAME is evaluated as appropriate when the underscore isn’t following immediately afterwards, but the extra space messes things up down the line.

Not Rick Astley

Posted 2010-08-23T22:00:15.643

Reputation: 13

If you want to get serious about bash shell scripts, you might want to read the Advanced Bash Scripting Guide (aka as "ABS").

– JanC – 2010-08-23T22:12:20.857

Answers

2

Use ${PRODUCT_NAME}_OBJC_FILES. The curly braces tell Bash explicitly where the variable name ends.

David Z

Posted 2010-08-23T22:00:15.643

Reputation: 5 688