ENV2(1)

πŸ“¦
version 1.1.0 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble

πŸ’– 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 computed SHA1 hash, kinda like the way git does versioning. So if you get a warning message about an inconsistent hash, it means somebody modified the file without updating the $SHA variable. 🚨 sus behaviour fr fr

πŸŽ€ OPTIONS πŸŽ€

  • -all β€” include all variables rather than just the ones that changed. go peek at -diff for 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, the SHELL environment variable is examined. If that fails too, we default to bash (hey, I had to choose something, and bash is the default Linux shell of choice). 🐚
  • -help β€” this built-in documentation. Written in POD so 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, env2 starts 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 a FILE to save the results in. By default results are sent to STDOUT. If you leave off the FILE, 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 $HOME if path not specified.
  • -reset β€” resets the ignore list to a minimum set. see also -clear, -ignore and -unsafe_clear. fresh start energy ✨
  • -save [FILE] β€” saves the environment in a perl format. By default saves to env2.pl. Internally, this option is invoked as part of the conversion process and saves an intermediate file to /tmp/env2.$$.pl. πŸ’Ύ
  • -sha1 β€” displays the SHA1 version 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, the SHELL environment variable is examined. If that fails, we default to bash (hey, I had to choose something, and bash is the default Linux shell of choice). 🐚
  • -uniq [PATHLIST] β€” ensure that each path variable specified in PATHLIST contains 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, -ignore and -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. πŸ”₯


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