From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Eager To: ciaran Cc: gcc@gcc.gnu.org Subject: Re: using linux environment variables such as $USER in c++ applications Date: Thu, 09 Aug 2001 16:21:00 -0000 Message-id: <3B731B13.AA54E917@mvista.com> References: <3B71F618.8070500@yahoo.com> X-SW-Source: 2001-08/msg00564.html ciaran wrote: > > how do i get the compiler to recognize variables like $PATH or $USER? i > wanna use them like how i would in a shell script This is probably off topic for the GCC mailing list. I presume you want to have a string which contains an environment variable which you want to expand to it's contents. For example: char * filename = "$USER/myfile"; You need to scan the string for occurances of environment variables: char * env = strchr (filename, '$'); Find the end of the environment variable (look at strspn()). Remove the environment variable from the string, save it somewhere, say in "env". Call getenv(env) to get the value of the environment variable, remembering to remove the '$'. Insert the value into the string where you removed the environment variable. There are similar functions in the C++ string class which you can use. -- Michael Eager eager@mvista.com 408-328-8426 MontaVista Software, Inc. 1237 E. Arques Ave., Sunnyvale, CA 94085