Environment variable substitution in Linux make


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Environment variable substitution in Linux make
# 1  
Old 07-08-2015
Environment variable substitution in Linux make

I know that I can do this in bash
Code:
ver=${VERSION:-$DEFVERSION}

so ver is $VERSION if it's set but $DEFVERSION if $VERSION isn't set

I want to do the same thing as a macro in a Makefile and can't get it to work - maybe something like...
Code:
VER=$(shell ${$(VERSION):-$(DEFVERSION)})

Any help appreciated
# 2  
Old 07-08-2015
You can use the ?= operator, which sets a variable if and only if it's not already set:

Code:
VAR ?= value

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to change Linux Terminal environment variable in a perl or bash script?

Hi, I meet an problem that it cannot change Terminal environment variable in a perl or bash script. This change can only exist and become effective in script lifetime. But I want to make this change take effect in current opened Terminal. In our view, the thought seems to be impossible, As... (9 Replies)
Discussion started by: weichanghe2000
9 Replies

2. Shell Programming and Scripting

Cannot make pipe for process substitution: Too many open files

Hi, I've came across an issue with a script I've been writing to check DHCP addresses on an Solaris system, the script has been running reasonably well, until it hit the following problem: ./sub_mon_v2: redirection error: cannot duplicate fd: Too many open files ./sub_mon_v2: cannot make... (3 Replies)
Discussion started by: CiCa
3 Replies

3. UNIX for Dummies Questions & Answers

setting a environment variable on linux

I want to set a enviroment variable VDC_DIR to a particular directory. I am doing it as export VDC_DIR=/abc it gets set but when i logout and do relogin than its not there. one way could be setting it in .profile file. but i have seen it on another box where it is not present in... (2 Replies)
Discussion started by: Jcpratap
2 Replies

4. Programming

Make: Bad Substitution

Hi, I have a make file which I try to execute, but it failed when it arrived to the line: for r in ${PIPESTATUS }; do if (($r != 0)); then exit $r; fi;done; With the Error: ""make:/bin/sh: Bad substitution"" Or the Error: "make:${PIPESTATUS[...}: Bad substitution" (Depend on the operating... (3 Replies)
Discussion started by: nadne
3 Replies

5. Shell Programming and Scripting

Expand an environment variable in sed, when the variable contains a slash

I'm trying to make a sed substitution where the substitution pattern is an environment variable to be expanded, but the variable contains a "slash". sed -e 's/<HOME_DIRECTORY>/'$HOME'/'This gives me the following error: sed: -e expression #1, char 21: unknown option to `s'Obviously this is... (2 Replies)
Discussion started by: Ilja
2 Replies

6. Shell Programming and Scripting

How to make Environment Variable Permanent ??

How can i set a environment variable in unix shell ?? I can set it using setenv or export but when i close & open the terminal again i couldn't see that environment variable, how can i make that change permanent ?? (1 Reply)
Discussion started by: chaditya
1 Replies

7. UNIX for Dummies Questions & Answers

How to make URLs/FileNames case insensitive in Linux Hosting environment

Hi, Currently my website is hosted on Linux-Apache environment. If I try to access a file on a website named "Read.txt" as http://xyz.com/READ.txt, I get an error message "Page Not Found". Only way to access is http://xyz.com/Read.txt. How do I make URLS (File Names and Folder Names)... (1 Reply)
Discussion started by: naidu545
1 Replies

8. Linux

How to create file on Linux using environment variable in the dirpath

Hi all, I am running a Java program on a Linux server in which I read in a base directory path from the *.properties file. During processing, I build a unique file name and create a file to save data, concatenating the directory path and the file name. Works fine, except that I now need to... (2 Replies)
Discussion started by: patricia1of5
2 Replies

9. Shell Programming and Scripting

How can I make running gawk scripts more user-friendly in a Windows environment?

I know, and I apologise for using the W word, but I have users asking if they can use my gawk scripts, but I just know they're not going to like using the DOS command line. Is there any way for me to run my gawk scripts from a gui? Even if it's from a web page (html, php, what ever). I do not... (3 Replies)
Discussion started by: jonathanm
3 Replies

10. Shell Programming and Scripting

Sed variable substitution when variable constructed of a directory path

Hello, i have another sed question.. I'm trying to do variable substition with sed and i'm running into a problem. my var1 is a string constructed like this: filename1 filerev1 filepath1 my var2 is another string constructed like this: filename2 filerev2 filepath2 when i do... (2 Replies)
Discussion started by: alrinno
2 Replies
Login or Register to Ask a Question