How could I read an environmental variable that a user has set?
I'm new to desktop development on the Mac (cocoa), and I am building a little tool that I can use to access amazon's s3 service.
I set my environmental variables in my .bash_profile, but I want this to work regardless of where the user entered it (.bashrc, .bash_profile or .profile etc).
On Windows In the command window that opens, enter echo %VARIABLE%. Replace VARIABLE with the name of the environment variable you set earlier. For example, to check if MARI_CACHE is set, enter echo %MARI_CACHE%. If the variable is set, its value is displayed in the command window.
Let's look at three of the main environmental variables that can influence perception: physiological, psychological, and social.
An environment variable is a variable whose value is set outside the program, typically through functionality built into the operating system or microservice. An environment variable is made up of a name/value pair, and any number may be created and available for reference at a point in time.
Look at the environment method on a NSProcessInfo. It returns a NSDictionary of the environment so e.g. for PATH
NSString* path = [[[NSProcessInfo processInfo]environment]objectForKey:@"PATH"];
You can use a C API from the GNU library http://www.gnu.org/software/libc/manual/html_node/Environment-Access.html#Environment-Access
converting to NSString: modern obj-c:
NSString *envVarString = @(getenv("__MY_ENV_NAME__"));
legacy obj-c:
NSString *envVarString = [NSString stringWithUTF8String: getenv("__MY_ENV_NAME__")];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With