Is there an equivalent to Python's expandvars in C?

Viewed 558

I have a string stored in a file that is read into a string. I wish to replace variables defined in *nix shell format with the corresponding environment values.

For example, an environment variable of $DEPLOY=/home/user will turn "deploypath=$DEPLOY/dir1" into "deploypath=/home/user/dir1"

Is there a simple library to do this?

i.e.

#include "supersimplelib.h"
char *newstr = expandvars(oldstr);

(or similar)

I understand I could use a regular expression lib and then call getenv() but I was wondering if there was another simpler way?

It will only be compiled under Linux.

1 Answers
Related