I am trying to append a path to the end of my PERL5LIB
environment variable, but I am not sure that this variable will always exist. If it doesn't exist I would like to simply initialize it to the value that I am trying to append.
Here is an example that works:
if ( $?PERL5LIB ) then
setenv PERL5LIB ${PERL5LIB}:/some/other/path
else
setenv PERL5LIB /some/other/path
endif
While this works, it still seems pretty clunky since I have to basically write the same line twice. What I would like to do is come up with a more efficient one line solution (possibly using parameter expansion).
Is there a way to consolidate this to one line? (Or a couple lines that don't involve writing out "/some/other/path" multiple times)
For example this could be done in bash:
export PERL5LIB=${PERL5LIB:+${PERL5LIB}:}/some/other/path
On Windows 7, just type "system" in the META-Prompt and you'll see an entry "Edit the System Environment Variables". From there, click "Environment variables". There, you can either edit the system variable PATH (bottom list) or add/edit a new PATH variable to the user environment variables.
To add a path to the PATH environment variableIn the System dialog box, click Advanced system settings. On the Advanced tab of the System Properties dialog box, click Environment Variables. In the System Variables box of the Environment Variables dialog box, scroll to Path and select it.
Depends on what value you would like to pass as part of environment variable. If its just key=value pair where value is not location path , then you just use -D option , just like how you do VM Args and run. Save this answer.
We can add a new path for all users on a Unix-like system by creating a file ending in . sh in /etc/profile. d/ and adding our export command to this file. All of the scripts in /etc/profile.
If the environment variable is not defined, set it to an empty string. This avoids duplication.
if ( ! $?PERL5LIB ) then
setenv PERL5LIB ""
else
setenv PERL5LIB "${PERL5LIB}:"
endif
setenv PERL5LIB ${PERL5LIB}/some/other/path
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