Photo by Wesley Ford on Unsplash

Linux: Edit Environment Variables on the Fly with varedit

Konstantinos Patronas

The varedit function is a versatile and user-friendly Bash function designed to simplify editing environment variables in memory using vipe, a utility from the moreutils package. With varedit, you can create or modify environment variables dynamically during your terminal session.

Overview of the Function

The varedit function creates or modifies environment variables in memory. Changes made using this function are session-specific and will not persist after the terminal session ends.

The varedit function performs the following tasks:

  1. Check for vipe Installation: Ensures vipe is installed on the system before proceeding.
  2. Verify Input: Confirms the function is called with exactly one parameter, the name of the environment variable to edit.
  3. Handle Non-Existent Variables: If the specified variable does not exist, it creates it as an empty variable.
  4. Edit Using vipe: Opens the current value of the environment variable in vipe for editing.
  5. Handle Changes: Updates the variable with the new value if changes are made. If no changes are made and the variable was created as empty, it unsets the variable.

Function Definition

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Written by Konstantinos Patronas

DevOps engineer, loves Linux, Python, cats and Rock music

No responses yet

What are your thoughts?