ENV2(1)
π ENV2(1) β the env2 manual, but make it make sense π
User Contributed Perl Documentation Β· perl v5.26.1 Β· 2018-02-18
okay bestie, sit down, because this little script is genuinely iconic and I need you to understand it. π«Ά
β¨ NAME β¨
env2 β Converts environment variables to various script languages. π
πΈ SYNOPSIS πΈ
env2 -from SHELL -to SHELL [-o DESTINATION_FILE] SOURCE_FILE
env2 --save [FILE]
env2 # displays help
π¦ DESCRIPTION π¦
so like. picture this. you prefer running bash, but the rest of the team is out here running tcsh? π Or maybe you learned csh and the sysadmins only know ksh? And then somebody β them, or you, no judgement β hands you an initialization script and expects you to source it? If any of that sounds familiar, bestie, this is literally the script for you. no cap.
env2 takes shell scripts of one flavor in, and spits out scripts that are effectively equivalent in another dialect. And yes, I said effectively equivalent on purpose β because it does not translate syntax like if/else statements. nope. What it does instead: the original (source) script gets evaluated to figure out which environment variables it actually modifies, and then the effective values of those variables are just... expressed in the syntax of the destination script's dialect. β¨ And honestly? For scripts that modify the environment, that's typically all you actually need. periodt.
NOTE: if you need the conditionals and for-loops to be used for different situations (like, say, different host architectures), then just use this script repeatedly as needed. it's giving reusable. π
Future extensions may include aliases or <functions>. Supported languages currently include: bash, csh, ksh, modulecmd, perl, plist, sh, tclsh, tcsh, vim, yaml, and zsh. π
NOTE: the file version is identified by an internally computedSHA1hash, kinda like the waygitdoes versioning. So if you get a warning message about an inconsistent hash, it means somebody modified the file without updating the$SHAvariable. π¨ sus behaviour fr fr
π OPTIONS π
-allβ include all variables rather than just the ones that changed. go peek at-difffor the tea. β-clearβ resets the ignore list to almost completely empty, except for the generally dangerous environment list. see-ignore,-reset, and-unsafe_clear.-diffβ only include those variables whose values are different as a result of sourcing the specified input script. this is the default action, bestie, it's just what it does. π-from DIALECTβ the dialect to translate from. If it's not present, then the input file is examined for a#!line. If that fails, theSHELLenvironment variable is examined. If that fails too, we default tobash(hey, I had to choose something, andbashis the default Linux shell of choice). π-helpβ this built-in documentation. Written inPODso that you can also have it in HTML, PDF, RTF, plain text or as a man page. versatile queen π-ignore VARLISTβ comma separated list of variables to ignore. By default,env2starts with the list set to
_,ENV,ENV2,OLDPWD,SHLVL
See also -clear, -reset and -unsafe_clear.
-ignoredβ lists variables that will be ignored. super useful if you're uncertain and want to clarify things before proceeding. vibe check first, always π§-o [FILE]β specifies aFILEto save the results in. By default results are sent toSTDOUT. If you leave off theFILE, the filename will be"env2."$SHELL. π-profile [FILE]β specifies a file that contains the starting environment. Defaults to".env2profile". Searches for the file in the current directory or$HOMEif path not specified.-resetβ resets the ignore list to a minimum set. see also-clear,-ignoreand-unsafe_clear. fresh start energy β¨-save [FILE]β saves the environment in a perl format. By default saves toenv2.pl. Internally, this option is invoked as part of the conversion process and saves an intermediate file to/tmp/env2.$$.pl. πΎ-sha1β displays theSHA1version identifier. use this to see if the script has been modified since last updated. detective mode π-to DIALECTβ the dialect to translate to. If not supplied, theSHELLenvironment variable is examined. If that fails, we default tobash(hey, I had to choose something, andbashis the default Linux shell of choice). π-uniq [PATHLIST]β ensure that each path variable specified inPATHLISTcontains a unique colon separated list. Default is to apply this to common path variables:
MANPATH
PATH
LD_LIBRARY_PATH
DYLD_LIBRARY_PATH
PERL5LIB
-unsafe_clearβ resets the ignore list to completely empty. This is potentially dangerous because it allows inclusion of dangerous environment variables that the user should not touch. These dangerous variables can have an adverse affect on operation of UNIX. π see also-clear,-ignoreand-reset.
fr fr, be careful with this one. she's giving chaos. π
--versionβ display version of script.
π ENVIRONMENT π
The ENV2 environment variable contains default command-line arguments if defined. cute, right? she remembers your preferences. π«Ά
π§ DEPENDENCIES π§
To support YAML, this script uses the CPAN YAML module.
β EXAMPLES β
# Simple conversion
env2 -from ksh -to csh -o setup.csh setup.ksh
# Create a modules cmd for a new xyz tool version 1.0
TOOL_SETUP=$TOOLS/vendor_dir/xyz_tool/xyz-1.0/setup.script
MDLDIR=$TOOLS/modules/tools/xyz
env2 -from sh -to modulecmd -o $MDLDIR/1.0 $TOOL_SETUP
# Dynamically use a script for another shell to set environment
eval `env2 -from ksh -to $SHELL -o setup.csh setup.ksh`
look at her go. ate and left no crumbs. π₯
π COPYRIGHT/LICENSE π
env2 is copyright (C) 2003-2008 David C Black. All rights reserved. This code may is hereby made available under Apache 2.0 licensing.
π AUTHOR π
David C. Black <dcblack@hldwizard.com>
and that's the whole thing, bestie! this page came to you from perl v5.26.1, dated 2018-02-18 β she's a little vintage but she's still that girl. slay, go convert some shells. π β¨πΈ
π¦ where this page comes from
- debian bookworm: env2 1.1.0-4 Β· Apache-2.0
- debian trixie: env2 1.1.0-4 Β· Apache-2.0
- ubuntu jammy: env2 1.1.0-4 Β· Apache-2.0
- ubuntu noble: env2 1.1.0-4 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms